I want to format a double to string with the max length is 7 which contains a dot "." and one digit after it.
For example:
123.4 becomes "00123.4"
12345 becomes "12345.0"
12345.63 becomes "12345.6"
Any help, please!
I want to format a double to string with the max length is 7 which contains a dot "." and one digit after it.
For example:
123.4 becomes "00123.4"
12345 becomes "12345.0"
12345.63 becomes "12345.6"
Any help, please!
you can do this:
double test = 33333.327;
String formatted = String.format("%07.1f", test)
System.out.println(formatted);
Try this -
DecimalFormat df = new DecimalFormat("00000.0");
...
System.out.println(df.format(123.4)); -> 00123.4
System.out.println(df.format(12345)); -> 12345.0
System.out.println(df.format(12345.63)); -> 12345.6
String.format("%07.1f", myDouble);
See http://docs.oracle.com/javase/8/docs/api/java/util/Formatter.html