public class ss {
public static void main(String[] args){
int a=45;
int b =102;
double c = (double)a/b*100;
double d = ((double)a/b)*100;
String str = "c=" + c + "%";
NumberFormat nf= new DecimalFormat( "#.00" );//可以定义数据的格式为保留两位小数
System.out.println( str );
System.out.println( "d=" + nf.format(d) + "%" );
public class ss {
public static void main(String[] args){
int a=45;
int b =102;
double c = (double)a/b*100;
String str = c + "%";
System.out.println(str);
}
楼上的已经是正确的了,只是补充一下,
int a=45;
int b=102;
double d=((double)a/b)*100;
NumberFormat nf= new DecimalFormat("#.00");//可以定义数据的格式为保留两位小数
System.out.println(nf.format(d)+"%");