Converting String to Decimal?

Asked

Viewed 40 times

2

I’m trying to convert a monetary value to decimal, the value 1.000,00. When I do the conversion and display only the whole number 100000 the decimal point no longer exists.

How to solve this ?

I’m trying like this.

string s = "1.000,00";
decimal d = decimal.Parse(s.Replace(".","").Replace(",", "."));
Console.WriteLine(d);
//console output = 100000
  • Alternative solution: http://answall.com/a/48425/101 One more customized: http://answall.com/a/44962/101

  • @bigown in case the link q vc flw are using for display I want to format to record in the database. In case of writing to the database should be with dot and not comma, correct ?

  • It doesn’t matter where it will be used. After it is converted to decimal, it is a number, there is no point.Number is not text.

  • I’ll test, whatever thing warning here.

  • You’re converting "1,000.00" to "1000.00" and then decimal, and at the last step you get 100000 as a result? Are you sure your environment recognizes "." as the decimal separator, or is using Brazilian format and expects "," there?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.