Java小数点問題
822 ワード
java :
java , , , , , 。
:
(float)a/b // ,
a/(float)b
(float)a/(float)b //
Java
float num= (float)2/3;
DecimalFormat df = new DecimalFormat("0.00");//
String s = df.format(num);// String
:
import java.text.NumberFormat;
public class TeachYou {
public static void main(String[] args) {
// “D” Double , ,
double percent = 50.5D / 150D;
// ,
System.out.println(" :" + percent);
//
NumberFormat nt = NumberFormat.getPercentInstance();
// 2
nt.setMinimumFractionDigits(2);
//
System.out.println(" :" + nt.format(percent));
}
}