int po=3366;
int len=242956;
double bb;
bb=po/len*100;
Double percent = new Double(double);
NumberFormat percentFormatter;
String percentOut;
percentFormatter = NumberFormat.getPercentInstance(new Locale("cn","CH"));
percentOut = percentFormatter.format(percent);
System.out.println(百分数是: + " " + currentLocale.toString());
int len=242956;
double bb;
bb=po/len*100;
Double percent = new Double(double);
NumberFormat percentFormatter;
String percentOut;
percentFormatter = NumberFormat.getPercentInstance(new Locale("cn","CH"));
percentOut = percentFormatter.format(percent);
System.out.println(百分数是: + " " + currentLocale.toString());
bb = ((float) po / len) * 100;
这里用到了一个强制(显式)类型转换以及一个隐式类型转换。
bb = (int) ( ((float) po/len) * 100);
int po=3366;
int len=242956;
double bb;
bb=(double)po/len;
Double percent = new Double(bb);
NumberFormat percentFormatter;
String percentOut;
percentFormatter = NumberFormat.getPercentInstance();
percentOut = percentFormatter.format(percent);
System.out.println("百分数是: "+ percentOut);
float bb=((float)(po*100))/242956;
使用java.lang.Math.round()可四舍五入。
我想 pp616 想要的是百分比输出吧!上面的那段程序就能输出百分比!如果po=3;len=4;则上面那段程序的输出结果为 75%
int len=242956;
long bb;
Integer bm = new Integer(po);
bb=bm.floatValue()/len*100;
好象你很悠闲啊?做什么工作?老板不管?
好象你很悠闲啊?做什么工作?老板不管?