In C#programming, the number of display places for accurately control the decimal number is very important, especially when dealing with currency and other values of the two digits after the decimal point.
Use the tostring () method
The
ToString()
method can be used:
ToString()
: Display two decimals and perform four houses and five entry (for example, 0.5m display as ".5").
decimalVar.ToString("#.##")
decimalVar.ToString("0.##")
Example decimalVar.ToString("0.00")
, with a value of 0.5m. Using the above method, you can display it as:
-& gt; "0.5"
-& gt; "0.50"
decimalVar
The above is the detailed content of How to precisely control the decimal places displayed in C#?. For more information, please follow other related articles on the PHP Chinese website!