This method gets the percentage after the decimal too much, 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%
Using this method is ideal, you can 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 ToString ("P") of this method preserves the two digits after the decimal point by default, which also gives you the desired number
Double percent=convert.todouble (2)/convert.todouble (34);
String result=percent. ToString ("P");//can go to the 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 that is 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%
Transfer from http://blog.sina.com.cn/s/blog_661beca00100subx.html
Two percent (RPM) in C #