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:
I ask: "% 1 $, .2 f" What does this mean?
Reply:
658 returns yes, 658.00
Reply:
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