当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java NumberFormat isGroupingUsed()用法及代码示例


isGroupingUsed()方法是java.text.NumberFormat的内置方法,如果按给定格式使用分组,则返回true,否则返回false。可以将数字567879的英语语言环境分组为“ 5、67、879”,其中大小取决于语言环境,并由其子类确定

用法

public boolean isGroupingUsed()

参数:该函数不接受任何参数。


返回值:该函数返回一个布尔值,如果可以以这种格式使用分组,则返回true,否则返回false。

下面是上述函数的实现:

示例1:

// Java program to implement 
// the above function 
  
import java.text.NumberFormat; 
import java.util.Locale; 
import java.util.Currency; 
  
public class Main { 
    public static void main(String[] args) 
        throws Exception 
    { 
  
        // Get the instance for Locale US 
        NumberFormat nF 
            = NumberFormat 
                  .getPercentInstance( 
                      Locale.US); 
  
        // Prints the hash-code value 
        if (nF.isGroupingUsed()) 
            System.out.println("Yes!"
                               + " grouping is used"); 
        else
            System.out.println("No!"
                               + " grouping is used"); 
    } 
}
输出:
Yes! grouping is used

示例2:

// Java program to implement 
// the above function 
  
import java.text.NumberFormat; 
import java.util.Locale; 
import java.util.Currency; 
  
public class Main { 
    public static void main(String[] args) 
        throws Exception 
    { 
  
        // Get the instance for Locale CANADA 
        NumberFormat nF 
            = NumberFormat 
                  .getPercentInstance( 
                      Locale.CANADA); 
  
        // Prints the hash-code value 
        if (nF.isGroupingUsed()) 
            System.out.println("Yes! "
                               + "grouping is used"); 
        else
            System.out.println("No! "
                               + "grouping is used"); 
    } 
}
输出:
Yes! grouping is used

参考: https://docs.oracle.com/javase/10/docs/api/java/text/NumberFormat.html#isGroupingUsed()



相关用法


注:本文由纯净天空筛选整理自gopaldave大神的英文原创作品 NumberFormat isGroupingUsed() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。