Does String.Format consider the locale or not?

Is it true that String.Format works in two ways: if we use an embedded format such as C, N, P .... will it take into account the locale settings? if we use custom format code like #, ## 0.000, will it not take into account the locale settings?

In my code I use this method

String.Format ("{0: #. ## 0,000}", value);

because my country uses a comma as a decimal separator

but the result is still equal: 1,234.500, as if he were considering the point as a decimal separator.

Please, help!

+7
source share
3 answers

Do you want to use CultureInfo :

value.ToString("N", new CultureInfo("vn-VN"));

String.Format:

String.Format(new CultureInfo("vi-VN"), "N", value);

( ), , vn-VN.

+19

.

IFormatProvider iFormatProvider = new System.Globalization.CultureInfo("es-ES");

string s = value.ToString("#,##0.000", iFormatProvider);

string s2 = string.Format(iFormatProvider, "{0:#,##0.000}", val)

, , . en-US, .ToString() string.Format() .

+3

Make sure your theme uses the right culture:

        Thread.CurrentThread.CurrentCulture = CultureInfo.CurrentCulture
        Thread.CurrentThread.CurrentUICulture = CultureInfo.CurrentCulture
        FrameworkElement.LanguageProperty.OverrideMetadata(GetType(FrameworkElement), New FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)))
0
source

All Articles