0

I need to make the application work according to system culture. But i have used many hardcoded value for Bit and byte conversion Like Dim maxlimit as double=4.999999.

When i change the cultureInfo for application the bit convertion is not proper. So I am looking for a solution How to use hard coded double values according to the system culture and to manipulate them? (like multiplication, division, addition).

I have used the below snippet to convert the value to Double according to system culture. i have set the Culture to "de-DE"

Code:

 Dim l_sDoubleValue As Double
 If String.Equals(CultureInfo.CurrentUICulture.ToString(), "de-DE",StringComparison.OrdinalIgnoreCase) Then

    l_sDoubleValue = Convert.ToDouble(p_sValue.ToString(CultureInfo.CurrentUICulture), CultureInfo.CurrentUICulture.NumberFormat)

 ElseIf String.Equals(CultureInfo.CurrentUICulture.ToString(), "en-US", StringComparison.OrdinalIgnoreCase) Then
    l_sDoubleValue = Double.Parse(p_sValue)
 End If

 Return l_sDoubleValue

Example:

  Value = 4.999999

When i convert the value to string using p_sValue.ToString(CultureInfo.CurrentUICulture) the output is 4,999999 but when i convert the value to Double the output is 4.999999

Pilgerstorfer Franz
  • 8,303
  • 3
  • 41
  • 54
Tamil
  • 23
  • 3
  • 2
    `Double`s don't have a format, and don't "retain" the culture information that was used to obtain them. It's really unclear to me what you're actually trying to do here. – Damien_The_Unbeliever Apr 28 '14 at 06:46
  • double value within your code will always look like 4.999 - When printed out (eg. to Console) - currentUICulture comes into count and same double value will look like 4,999 - everything looks ok to me. So what's your problem? – Pilgerstorfer Franz Apr 28 '14 at 06:49
  • @ Pilgerstorfer Franz :Thanks for your reply. I am getting input from the Textbox which accept the value according to system culture so my problem is will it return right value when used in arithmetic operations. for example 4.999999*2.03 =10.14999797 the same value will be returned when we change the cultureinfo? – Tamil Apr 28 '14 at 06:58

0 Answers0