Tuesday, February 18, 2014

How to convert 123,456 this form 123456


As the title belongs, put a float type data into a string 12,345,678.90 this form?<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
 String.format ("% 1 $, .2 f", 12345678.9) 

Reply:
 String formatFloat (float num) {
StringBuffer buf = new StringBuffer (Float.toString (num));
buf = buf.reverse ();
int dotPos = buf.indexOf (".");
final int start = dotPos == -1 0: dotPos;
?StringBuffer sb = new StringBuffer ();
for (int i = 0; i if ((i - start)% 3 == 0 && (i -! start) = 0) {
sb.append (',');
}
sb.append (buf.charAt (i));
}
return sb.reverse () toString ();.
}


Reply:
 
float f = 12345678.9f;
String str = String.format ("% .2 f", f) replaceAll. (, "," "(= (\ \ D {3}) + \ \)?.");

Reply:
 
NumberFormat numberFormat = new DecimalFormat ("# # # #, # # #");
System.out.println (numberFormat.format (Integer.parseInt ("1234564589")));


Note that the length of type int
Reply:
DecimalFormat good
Reply:
cited a floor tantahe reply:
 String.format ("% 1 $, .2 f", 12345678.9) 


I ask: "% 1 $, .2 f" What does this mean?
Reply:
reference to the third floor hjywyj reply:
 
float f = 12345678.9f;
String str = String.format ("% .2 f", f) replaceAll. (, "," "(= (\ \ D {3}) + \ \)?.");

658 returns yes, 658.00
Reply:
reference to the 6th floor knxw0001 reply:
Quote: references to a floor tantahe reply:

 String.format ("% 1 $, .2 f", 12345678.9) 


I ask: "% 1 $, .2 f" What does this mean?

1 $ represents the first argument behind that 12345678.9
Before, which means that every three decimal places separated by commas
.2 F represents two digits after the decimal point
Reply:
mark about the study.

No comments:

Post a Comment