Get two percent in C #

Source: Internet
Author: User

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 #

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.