Few different ways how you can format a decimal number (float, double, or decimal).
Setting the Maximum Allowed Decimal Places:
To format your numbers to a maximum of two decimal places use the format string {0:0.##} as shown in the below example:
string.Format("{0:0.##}", 256.583); // "256.58"
string.Format("{0:0.##}", 256.586); // "256.59"
string.Format("{0:0.##}", 256.58); // "256.58"
string.Format("{0:0.##}", 256.5); // "256.5"
string.Format("{0:0.##}", 256.0); // "256"
Setting a Fixed Amount of Decimal Places:
This is similar to the above example but instead of hashes (‘#’) in our format string we are going to use zeroes (‘0’) as shown below:
string.Format("{0:0.00}", 256.583); // "256.58"
string.Format("{0:0.00}", 256.586); // "256.59"
string.Format("{0:0.00}", 256.58); // "256.58"
string.Format("{0:0.00}", 256.5); // "256.50"
string.Format("{0:0.00}", 256.0); // "256.00"
The Thousand Separator:
To format your decimal number using the thousand separator, use the format string {0:0,0} as shown in the below example:
string.Format("{0:0,0.00}", 1234256.583); // "1,234,256.58"
string.Format("{0:0,0}", 1234256.583); // "1,234,257"