Tuesday, September 29, 2015

Be careful of the number of decimal places you hand into {0:P} formatting for percentages in C#.

This suggests that .ToString("P", CultureInfo.InvariantCulture)); is going to use the first two decimal places as the first two digits of the percentage so if you want to show a percentage with two decimal places you need to Math.Round what you hand in to four decimals places instead of two. Does that make sense?

No comments:

Post a Comment