Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Mix up in CultureInfo
Message
From
10/09/2015 11:30:46
 
 
To
10/09/2015 08:11:27
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:
01624454
Views:
27
>>What properties of CultureInfo (other than NumberFormatInfo) affect the returned value ?
>
>I think it was related when I standardized two methods. Here is one for the currency display:
>
>
>    ' Format a value for a dollar
>    ' expN1 Value
>    ' expC1 Separator
>    Public Function GetFormatValueDollar(ByVal tnValue As Double, ByVal tcSeparator As String) 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.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
>
>
>In there, I am using the culture info for the display of the dollar sign. So, for the other method, I simply followed the same approach. I believe this suggestion came from here BTW.

My suggestion was only good for "N" format - you didn't mention Currency. Not sure where your 'nLanguage' is set - presumably at the session level ?
If I was looking for the same functionality I'd probably do :
Public Structure Cultures
	Public Const English As String = "en-US"
	Public Const French As String = "fr-CA"
	Public Const Spanish As String = "en-US"
	Public Const Portuguese As String = "en-US"
End Structure
set nLanguage to Cultures.French (or whatever) then
Public Shared Function GetFormatValue(tnValue As Double, tcSeperator As String, tnDecimal As Integer) As String
	Dim nfi As NumberFormatInfo = New CultureInfo(nLanguage).NumberFormat
	nfi.NumberDecimalSeparator = "."
	nfi.NumberGroupSeparator = tcSeperator
	nfi.NumberDecimalDigits = tnDecimal

	Select Case nLanguage
		Case Cultures.French
			If True Then
				nfi.CurrencyPositivePattern = 1
				Exit Select
			End If
	End Select

	Return tnValue.ToString("C", nfi)
End Function
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform