Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Mix up in CultureInfo
Message
From
09/09/2015 04:58:51
 
 
To
08/09/2015 13:56:58
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
VB 9.0
OS:
Windows 8.1
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01624382
Message ID:
01624388
Views:
48
>My framework main application class is defining those properties:
>
>
>    Public oCultureInfoEnglish As CultureInfo = Nothing
>    Public oCultureInfoFrench As CultureInfo = Nothing
>    Public oCultureInfoSpanish As CultureInfo = Nothing
>    Public oCultureInfoPortuguese As CultureInfo = Nothing
>
>
>The values are this:
>
>
>        oCultureInfoEnglish = New CultureInfo("en-US")
>        oCultureInfoFrench = New CultureInfo("fr-CA")
>        oCultureInfoSpanish = New CultureInfo("en-US")
>        oCultureInfoPortuguese = New CultureInfo("en-US")
>
>
>I have a function to display a numeric value as follow:
>
>
>    ' Format a value
>    ' expN1 Value
>    ' expC1 Separator
>    ' expN2 Number of decimals
>    Public Function GetFormatValue(ByVal tnValue As Double, ByVal tcSeparator As String, _
>     ByVal tnDecimal As Integer) As String
>        Dim lcValue As String = ""
>        Dim loCultureInfo As CultureInfo = Nothing
>
>        ' Based on the language
>        Select Case nLanguage
>
>            ' English
>            Case 1
>                loCultureInfo = oApp.oCultureInfoEnglish
>
>                ' French
>            Case 2
>                loCultureInfo = oApp.oCultureInfoFrench
>
>                ' Spanish
>            Case 3
>                loCultureInfo = oApp.oCultureInfoSpanish
>
>                ' Portuguese
>            Case 4
>                loCultureInfo = oApp.oCultureInfoPortuguese
>
>        End Select
>
>        loCultureInfo.NumberFormat.NumberDecimalSeparator = "."
>        loCultureInfo.NumberFormat.NumberGroupSeparator = tcSeparator
>        loCultureInfo.NumberFormat.NumberDecimalDigits = tnDecimal
>
>        lcValue = tnValue.ToString("N", loCultureInfo)
>
>        Return lcValue
>    End Function
>
>
>On some very rare situations, I have found that my value is being shown such as 30.000 where it should be 30.
>
>There seems to be a mixup of the memory in the usage of this culture info.
>
>My method receives 0 for the tnDecimal parameter. So, by looking at this method, it should be displayed 30 and not 30.000. The only time I should have decimals is if the method receives 3, for example, as the tnDecimal parameter value, which would then end up with 30.000.
>
>As this is random, and on a very rare occasions, I am assuming this is a memory issue. I cannot reproduce this. I have observed this twice and at first I thought I had seen it wrong. But, when I saw it a second time, I figured something is wrong.
>
>Anyone would know what could be wrong here?

Don't know - unless it's a threading issue. But it seems to me your method is overly complicated - you could just use NumberFormatInfo directly without needing a Culture info:
Public Shared Function GetFormatValue(tnValue As Double, tcSeperator As String, tnDecimal As Integer) As String
	Return tnValue.ToString("N", New NumberFormatInfo() With { _
		Key .NumberDecimalSeparator = ".", _
		Key .NumberGroupSeparator = tcSeperator, _
		Key .NumberDecimalDigits = tnDecimal _
	})
End Function
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform