Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display phonenumber using decimal format [duplicate]

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 "### ## ##"

like image 450
Yoda Avatar asked Nov 24 '22 01:11

Yoda


1 Answers

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);
like image 123
assylias Avatar answered Nov 26 '22 14:11

assylias