Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combining C# String.Format format options

I'd like to format my number as a percent value with an always visible sign.

To format it as a percent value I can do:

string.Format("{0:P2}", 1.45);

For visible signs I'll do:

string.Format("{0:+#.##;-#.##;0}", 1.45);

Any way to combine the two?

like image 300
user1255410 Avatar asked Feb 07 '26 08:02

user1255410


1 Answers

You probably just want to add % to custom format:

string.Format("{0:+#.##%;-#.##%;0}", 1.45); // output +145%
like image 61
Sinatr Avatar answered Feb 09 '26 08:02

Sinatr