DecimalFormat getGroupingSize() method in Java
The getGroupingSize() method is a built-in method of the java.text.DecimalFomrat class in Java and is used to get the grouping size for this DecimalFormat instance. The grouping size is defined as the number of digits present between grouping separators in the integer portion of a number. For example, in the number “123, 456.78”, the grouping size is 3
Syntax:
public int getGroupingSize()
Parameters: The function does not accepts any parameter.
Return Value: The function returns the grouping size for this DecimalFormat instance as an integral value.
Below is the implementation of the above function:
Program 1:
import java.text.DecimalFormat;
import java.util.Currency;
import java.util.Locale;
public class Main {
public static void main(String[] args)
{
DecimalFormat deciFormat = new DecimalFormat();
System.out.println(deciFormat.getGroupingSize());
}
}
|
Program 2:
import java.text.DecimalFormat;
import java.util.Currency;
import java.util.Locale;
public class Main {
public static void main(String[] args)
{
DecimalFormat deciFormat = new DecimalFormat();
deciFormat.applyPattern( "##, ##" );
System.out.println(deciFormat.getGroupingSize());
}
}
|
Reference: https://docs.oracle.com/javase/7/docs/api/java/text/DecimalFormat.html#getGroupingSize()
Last Updated :
01 Apr, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...