开发者

C# format currency with leading spaces?

开发者 https://www.devze.com 2023-03-12 05:28 出处:网络
I am trying to duplicate a text report that was written in Icon in 开发者_StackOverflowC#. The report has:

I am trying to duplicate a text report that was written in Icon in 开发者_StackOverflowC#. 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号