Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String formatting: negative/positive floating point numbers

How can I use String.Format in C# so doubles are displayed like this:

example:
___-1.000
____1.000
__100.123
-1000.321
_1000.214

etc...

Where _ is space (" ");

All I can do is String.Format("{0:F3}", -123.321);

like image 775
Miko Kronn Avatar asked Feb 26 '23 16:02

Miko Kronn


1 Answers

You can use alignment:

String.Format("{0,10:F3}", -123.321)

where 10 is preffered length.

See Composite Formatting.

like image 184
Athari Avatar answered Feb 28 '23 05:02

Athari