Format decimal number and InvariantCulture?

I want to format the number using ToString(CultureInfo.InvariantCulture) as well as up to 5 decimal places, which can be done using ToString("N5") . How can I do both together?

+5
source share
2 answers

How to use overload that accepts both format and culture :

 decimal m = 123.4567890123m; string x = m.ToString("N5", CultureInfo.InvariantCulture); 

(Obviously, replace double with decimal if you use this; equivalent overload .)

+14
source

If you have decimal, not double:

 string.Format(CultureInfo.InvariantCulture, "{0:f5}", m) 

like Decimal.ToString () does not have these overloads

0
source

All Articles