Hello I would like to use DecimalFormat to display:
8392472
as
839 24 72
I have tried
DecimalFormat dc = new DecimalFormat("000 00 00");
return dc.format(number);
I have also tried "### ## ##"
Hello I would like to use DecimalFormat to display:
8392472
as
839 24 72
I have tried
DecimalFormat dc = new DecimalFormat("000 00 00");
return dc.format(number);
I have also tried "### ## ##"
I don't think you can do that with a DecimalFormat
because your spaces are not group or decimal separators.
The simple way would be to simply use a string:
int number = 8392472;
String s = String.valueOf(number);
String formatted = s.substring(0, 3) + " "
+ s.substring(3, 5) + " "
+ s.substring(5, 7);
I think easiest way to achieve this is as below.
public static void main(String[] args) {
int number = 8392472;
StringBuilder sb = new StringBuilder(String.valueOf(number))
.insert(3," ")
.insert(6," ");
System.out.println(sb.toString());
}