Reputation: 251
I need to format the string as %
but the user will enter the number already as %
i.e user enter 10
, I need to show 10%
I tried {0:P}
and {0:0%}
but it always multiply the user number by 100
How can I simply add "%"
to the input number without multiply it by 100
in the format {0:}?
Upvotes: 4
Views: 2692
Reputation: 93
We use this format for formatting int value to percent without multipying by 100.
intPercent.ToString(@"0\%");
Upvotes: 0
Reputation: 3626
What about
var showString = userInput + "%";
Then display showString
wherever you need to show.
Upvotes: 1
Reputation: 127543
You have two real options, add the % by hand
String.Format("Example: {0}%", userValue);
or devide the user number by 100 before you display it.
String.Format("Example: {0:P}", userValue / 100.0); //don't just do "100" or you will get errors from integer division if userValue is a int.
Upvotes: 4