Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String formatting: scale and precision from String.Format

I need to format numbers (using WPF converters), and the only way I can do it is via string.Format.

I have two formatting parameters: scale and precision. I can achieve what I need separately, but it doesn't work with both:

Example (that works):

string.Format("{0:#,##0,,}", 1234567890.123m) == "1,235"
string.Format("{0:#,#.000}", 1234567890.123m) == "1,234,567,890.123"

What I need:

string.Format("????", 1234567890.123m) == "1,234.568"

(which would mean 1,234.568 Millions) As you can see I can't find a format pattern that would both scale and also display decimals.

Any idea?

like image 995
Antoine Jaussoin Avatar asked Jul 31 '12 15:07

Antoine Jaussoin


1 Answers

A colleague of mine got the solution:

string.Format("{0:#,##0,,.000}", 1234567890.123m) == "1,234.568"
like image 63
Antoine Jaussoin Avatar answered Oct 13 '22 11:10

Antoine Jaussoin