Reputation: 5029
I have a decimal that can can contain the following values and expected results
Basically I would like at least 2 decimal points if there is 2 or less and all if there is more (with 0's trimmed from the end) And if there is more than 3 digits I would like to add a comma, if there is less than 3 then nothing unless that value is less than 1 then add 00 infront
I have tried
private string FormatNumber(decimal number)
{
return number.ToString("#,###.########");
}
Upvotes: 0
Views: 197
Reputation: 37066
Your format string should be "#,###.00######"
.
Zero for "fill in with zero if there's less actual precision". Once you've started specifying what goes to the right of the decimal point, I'm afraid there's no way to specify "all the digits" other than just adding a great pile of #
.
Upvotes: 2