String.format() to format double in Java
How can I use String.format(format, args)
to format a double like below?
2354548.235
-> 2,354,548.23
String.format("%1$,.2f", myDouble);
String.format
automatically uses the default locale.
String.format("%4.3f" , x) ;
It means that we need total 4 digits in ans , of which 3 should be after decimal . And f is the format specifier of double . x means the variable for which we want to find it . Worked for me . . .