Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format string % without multiply the value by 100

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:}?

like image 965
Nullbyte Avatar asked Oct 17 '25 03:10

Nullbyte


2 Answers

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.
like image 169
Scott Chamberlain Avatar answered Oct 18 '25 20:10

Scott Chamberlain


Can't you just append %:

userEnteredNumber.ToString() + "%";
like image 23
Szymon Avatar answered Oct 18 '25 18:10

Szymon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!