當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。