java里面怎么format number?double i,j;
要把i/j的结果format成含有2位小数的格式, 例如 3.03, 4.00, 120.32 之类的格式.
请问怎么做?
Thanks~
Quite lots of ways..^^^
Try to get familiar with some funny stuffs, like:
class test {
public static void main (String args[]) {
double i = 0.5;
double j = 0.3;
Double result = new Double (i/j);
String output = result.toString();
int index = output.indexOf('.');
System.out.println (output.substring(0,index+1+2));
}//main
}
class test {
public static void main (String args[]) {
double i = 0.5;
double j = 0.3;
Double result = new Double (i/j);
String output = result.toString();
int index = output.indexOf('.');
System.out.println (output.substring(0,index+1+2));
}//main
}