Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Weird behavior on localization
Message
From
30/07/2010 07:14:22
 
 
To
30/07/2010 04:12:22
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01474524
Message ID:
01474582
Views:
49
This message has been marked as the solution to the initial question of the thread.
>>Are you setting the culture on the server or using Browser settings ?
>>It sounds as if this is more likely to be a browser issue......
>
>The DLL is using the Format() method built in the .NET Framework 4.0. So, when comes time to format a value such as $12.95, I am using the Format() method. Basically, it goes like this. I am calling the GetFormatValueDollar(), which calls GetFormat() to obtain the desired format so to pass it to the base method after. For some kind of reason, once I compile, it could be a dot or a comma. Sometimes, I will see a dot 4 times in a row. Then, on the next compile, I see a comma, such as $12,95.
>
>
>        ' Format a value
>        ' expC1 Separator
>        ' expN2 Number of decimals
>        Public Function GetFormat(ByVal tcSeparator As String, ByVal tnDecimal As Integer) As String
>            Dim lcFormat As String = ""
>            Dim lnCounter As Integer = 0
>
>            ' Obtain formatted value
>            For lnCounter = 1 To 9
>                lcFormat = "#" + lcFormat
>
>                If lnCounter Mod 3 = 0 Then
>                    lcFormat = tcSeparator + lcFormat
>                End If
>
>            Next
>
>            lcFormat = lcFormat + "0"
>
>            ' If we have decimals
>            If tnDecimal > 0 Then
>                lcFormat = lcFormat + "." + "".PadRight(tnDecimal, "0")
>            End If
>
>            Return lcFormat
>        End Function
>
>        ' Format a value for a dollar
>        ' expN1 Value
>        ' expC1 Separator
>        Public Function GetFormatValueDollar(ByVal tnValue As Double, ByVal tcSeparator As String) As String
>            Dim lcFormat As String = ""
>            Dim lcValue As String = ""
>            Dim llDollarSignToTheRight As Boolean = True
>
>            lcFormat = GetFormat(tcSeparator, 2)
>            lcValue = Format(tnValue, lcFormat) + "$"
>
>            ' If we format the dollar sign as per the language
>            If oApp.lFormatDollarAsPerTheLanguage Then
>
>                ' Based on the language
>                Select Case nLanguage
>
>                    ' English
>                    Case 1
>                        lcValue = "$" + Format(tnValue, lcFormat)
>
>                        ' French
>                    Case 2
>                        lcValue = Format(tnValue, lcFormat) + "$"
>
>                        ' Spanish
>                    Case 3
>                        lcValue = Format(tnValue, lcFormat) + "$"
>
>                        ' Portuguese
>                    Case 4
>                        lcValue = Format(tnValue, lcFormat) + "$"
>
>                End Select
>
>            End If
>
>            Return lcValue
>        End Function
>
I guess that boils down to this line:
lcValue = Format(tnValue, lcFormat) + "$"
which is using the legacy Microsoft.VisualBasic.Strings stuff. I don't really remember how that worked but I think it translates based on the Windows locale rather then the .NET current culture. Why not just use the .NET .ToString() methods e.g.:
Public Function GetFormatValueDollar(ByVal tnValue As Double, ByVal nLanguage As Integer) As String
        Dim info As CultureInfo
        Select Case nLanguage
            Case 1
                info = New CultureInfo("en-US")
            Case Else
                info = New CultureInfo("fr-CA")
                ' If you want different separators:
                info.NumberFormat.CurrencyDecimalSeparator = "."
                info.NumberFormat.CurrencyGroupSeparator = ","

        End Select
        Return tnValue.ToString("c", info)
    End Function
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform