This question already has an answer here:
I want to obtain number in following format:
1000 = 1,000
10000 = 10,000
100000 = 1,00,000
I tried this:
import java.text.DecimalFormat;
public class StringProcessingDemo {
public static void main(String[] args) {
String pattern = "##,##,###.###";
DecimalFormat myFormatter = new DecimalFormat(pattern);
String output = myFormatter.format(2564484.125);
System.out.println(output);
}
}
But despite of pattern ##,##,###.###
I am getting output as 2,564,484.125
while I think I should get it as 25,64,484.125
. Why?
This may be because of number format: million, billion, and trillion...... So, I have created a java function for your need:
You can supply multiple grouping characters, but only one is used. From the Javadoc:
It seems that formatting the Lakh format is not possible with standard Java mechanisms, see Number formatting in java to use Lakh format instead of million format for a solution.
You can achieve your requirement with this