Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format a number with X decimal places and InvariantCulture?

I want to format a number using ToString(CultureInfo.InvariantCulture) and also to 5 decimal places, which can be done using ToString("N5"). How can I do both together?

like image 756
grady Avatar asked Oct 19 '10 08:10

grady


1 Answers

How about using the overload which takes both a format and a culture:

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

(Obviously substitute double for decimal if you're using that; there's an equivalent overload.)

like image 63
Jon Skeet Avatar answered Oct 19 '22 18:10

Jon Skeet