The percentage after this method gets too many decimals, no
Double percent=convert.todouble (2)/convert.todouble (34);
String result= (percent*100). ToString () + "%";//Get 5.8823529411764%
This method can get the number of decimal places you want
Double percent=convert.todouble (2)/convert.todouble (34);
String result=string. Format ("{0:0.00%}", percent);//Get 5.88%
String result=string. Format ("{0:0.0000%}", percent);//Get 5.8824%
This is the ideal way to get the number of decimal places you want.
Double percent=convert.todouble (2)/convert.todouble (34);
String result=percent. ToString ("0%");//Get 6%
String result=percent. ToString ("0%");//Get 5.882%
The parameter P in this method tostring ("P") retains the two digits after the decimal point by default, which also gives you the ideal number double percent=convert.todouble (2)/convert.todouble (34);
String result=percent. ToString ("P");//Can reach 5.88%
String result =percent. ToString ("P2");//Get 5.88%
String result=percent. ToString ("P3");//Get 5.882%
Math.Round (num1,num2) method, parameter one (NUM1) is the number used for rounding, and parameter two (NUM2) is the number of digits that represent the number after the decimal point is reserved
Double Percent=math.round (2*1.00/34*100.0,4);
String result=percent. ToString () + "%";//Get 5.8824%
Transferred from http://blog.sina.com.cn/s/blog_661beca00100subx.html