Display floating point number in percent without changing the value of the number

Can I specify options string.Format()for adding a percent symbol without changing the value of a number?

Example:
We have a number 44.36and want to show in the grid and output in Excel as "44.36%". Dividing the value by 100and then applying the format is "P"not an option. In this case, changing the values ​​cannot be performed, we must do this only by changing the value DisplayFormat. Use is string.Format("{0}%", valueParam)also not an option.

+5
source share
1 answer

. '%' '\\', .

var number = 44.36m;
var formatted = number.ToString("0.##\\%"); // "44.36%"
// format string @"0.##\%" works too

// using String.Format()
var sformatted = String.Format("{0:0.##\\%}", number); // "44.36%"
+11

All Articles