Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# format currency with leading spaces?

I am trying to duplicate a text report that was written in Icon in C#. The report has:

Blah Blah........ $  10,938.09
Blah Blah........ $       3.88
Blah Blah........ $ 102,398.11

I am able to use multiple formatting calls to achieve this result with out issue, for example:

Console.WriteLine(string.Format("Blah Blah.....${0,10}", number.ToString("#,##0.00")));

but I would think there is a way to do it with just one call to string.Format(). Any idea how to insert leading spaces in a currency format?

like image 256
jeremy Avatar asked Jan 28 '26 12:01

jeremy


1 Answers

You do it like so:

Console.WriteLine(string.Format("Blah Blah.....${0,10:#,##0.00}", number));

Update:

This is the relevant part of the documentation.

like image 145
Jon Avatar answered Jan 30 '26 00:01

Jon



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!