خرید بک لینک

Vote count: 0

I am currently stuck with a Number formatting issue and I really don't know how to solve it.

I use a function from the Support assembly :

'StringToFormat looks like "123.456789"
'FormatInfo looks like "0.000" (must display three decimals)
Support.Format(StringToFormat, FormatInfo)

It works fine exept that when my regional settings are not set properly, it doesn't work... StringToFormat is a variable that come from another application (over TCP/IP) and I can't change it. So when the Decimal Separator is set to coma instead of a dot, the Format function is doing weird stuff and not displaying my values correctly.

To solve this, I wrote a small function that actually creates a new culture and makes sure that the decimal separator is the dot :

Sub UpdateRegionalSettings()
    'I call this everytime I start my application
    My.Application.ChangeCulture("x-en-US-custom")
End Sub

Sub CreateMyCulture()
    'This function is called only if the culture doesn't exist yet
    Dim C As New CultureAndRegionInfoBuilder("x-en-US-custom", CultureAndRegionModifiers.None)
    C.LoadDataFromCultureInfo(New CultureInfo("en-US"))
    C.LoadDataFromRegionInfo(New RegionInfo("US"))
    C.NumberFormat.NumberDecimalSeparator = "."
    C.NumberFormat.CurrencyDecimalSeparator = "."
    C.Register()
End Sub

However, this doesn't seem to work as when I go to regional settings and change the separator to a coma the Format function is going weird again. It is like these parameters override anything I can say in my program...

My question is : How can I force the Support.Format (and others) function to use the dot as a decimal separator without having to manually set it into region and language of the control panel ?

asked 2 mins ago

برچسب: نویسنده: استخدام کار تاريخ: چهارشنبه 1 ارديبهشت 1395 ساعت: 18:40

صفحه بندی