Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Weird behavior on localization
Message
De
03/08/2010 04:03:12
 
 
À
03/08/2010 02:59:35
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01474524
Message ID:
01474931
Vues:
34
>I have adjusted and it works. This is what I have now:
>
>
>        ' 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 = New CultureInfo("en-US")
>
>                    ' French
>                Case 2
>                    loCultureInfo = New CultureInfo("fr-CA")
>
>                    ' Spanish
>                Case 3
>                    loCultureInfo = New CultureInfo("en-US")
>
>                    ' Portuguese
>                Case 4
>                    loCultureInfo = New CultureInfo("en-US")
>
>            End Select
>
>            loCultureInfo.NumberFormat.NumberDecimalSeparator = "."
>            loCultureInfo.NumberFormat.NumberGroupSeparator = tcSeparator
>            loCultureInfo.NumberFormat.NumberDecimalDigits = tnDecimal
>
>            lcValue = tnValue.ToString("N", loCultureInfo)
>
>            Return lcValue
>        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 loCultureInfo As CultureInfo = Nothing
>            Dim lcValue As String = ""
>
>            ' Based on the language
>            Select Case nLanguage
>
>                ' English
>                Case 1
>                    loCultureInfo = New CultureInfo("en-US")
>
>                    ' French
>                Case 2
>                    loCultureInfo = New CultureInfo("fr-CA")
>
>                    ' Spanish
>                Case 3
>                    loCultureInfo = New CultureInfo("en-US")
>
>                    ' Portuguese
>                Case 4
>                    loCultureInfo = New CultureInfo("en-US")
>
>            End Select
>
>            loCultureInfo.NumberFormat.CurrencyDecimalSeparator = "."
>            loCultureInfo.NumberFormat.CurrencyGroupSeparator = tcSeparator
>
>            ' If we format the dollar sign as per the language
>            If oApp.lFormatDollarAsPerTheLanguage Then
>
>                ' Based on the language
>                Select Case nLanguage
>
>                    ' English
>                    Case 1
>
>                        ' French
>                    Case 2
>                        loCultureInfo.NumberFormat.CurrencyPositivePattern = 1
>
>                        ' Spanish
>                    Case 3
>
>                        ' Portuguese
>                    Case 4
>
>                End Select
>
>            End If
>
>            lcValue = tnValue.ToString("C", loCultureInfo)
>
>            Return lcValue
>        End Function
>
You could simplify by creating a custom culture for re-use whenever needed. eg:
ublic Class CustomCultures
    Private Shared mCanadian As System.Globalization.CultureInfo = Nothing
    Public Shared ReadOnly Property ModifiedCanadian() As System.Globalization.CultureInfo
        Get
            If mCanadian Is Nothing Then
                mCanadian = New CultureInfo("fr-CA")
                mCanadian.NumberFormat.CurrencyPositivePattern = 1
                'Any other mods
            End If
            Return mCanadian
        End Get
    End Property
    'Other possible modified cultures.....
End Class
Then all you would need would be:
Dim info As CultureInfo = New CultureInfo("en-US")
        Select Case nLanguage
            Case 1
                'English
            Case 2
                'French
                info = CustomCultures.ModifiedCanadian
            Case 3
                'Etc
        End Select
        Return tnValue.ToString("c", info)
Or, of course actually add a custom culture to the machine using CultureAndRegionInfoBuilder (but that might be overkill)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform