-2

So im trying to convert the string to a double but everytime it converts the string its missing the dot. This is for a currency calculataor.

My code:

 private void listBoxLeft_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        var valuta = listBoxLeft.SelectedItem.ToString();
        var valutaCurrencySplit = valuta.Split(':');
        var currency = valutaCurrencySplit[1];
        currency = currency.Replace(" ", String.Empty);

        Problem starts here...

        double finalNumber = Convert.ToDouble(finalString);

        Console.WriteLine(finalNumber);
    }

finalNumber ends as 74361, but should be 7.4361

uk3ndt
  • 57
  • 6

1 Answers1

3

You can use this:

string finalString = "7.4361";
decimal finalNumber = decimal.Parse(finalString, System.Globalization.CultureInfo.InvariantCulture);

// 7.4361
Gustav
  • 53,498
  • 7
  • 29
  • 55