tags:

views:

127

answers:

1

Does anyone know how to get number (or currency) format string (like "###,###,##0.00) from .NET NumberFormatInfo class? My research so far says that it should be constructed manually from the NumberFormatInfo class, but it sounds strange to me that Microsoft (or anyone else) didn't write anything for that purpose, so far.

+1  A: 

Try this:

var number = System.Globalization.CultureInfo.CurrentCulture.NumberFormat;
string format = 
    String.Format("{0}{1}{2}",
        String.Join(
            number.NumberGroupSeparator, 
            number.NumberGroupSizes.Select(group => new String('#', group))),
        number.NumberDecimalSeparator,
        new String('0', number.NumberDecimalDigits));
Rubens Farias
Thanks Rubens, good code snippet. It looks like that there is really no other way but to do this manually, like you did in this code.
vucetica
yeah; it smells bad, but sounds good.
Rubens Farias