NumberFormat isGroupingUsed() method in Java with Examples
The isGroupingUsed() method is a built-in method of the java.text.NumberFormat returns true is grouping is used in the given format, else it returns false. The grouping in English Locale for a number 567879 can be done as “5, 67, 879”, where the size if locale dependent and is determined by its subclass
Syntax:
public boolean isGroupingUsed()
Parameters: The function does not accepts any parameter.
Return Value: The function returns a boolean value, it returns true if grouping can be used in this format, else false.
Below is the implementation of the above function:
Program 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" ); } } |
Output:
Yes! grouping is used
Program 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" ); } } |
Output:
Yes! grouping is used
Reference: https://docs.oracle.com/javase/10/docs/api/java/text/NumberFormat.html#isGroupingUsed()
Please Login to comment...