-1

I have string value of "2.000,65" in German (de-DE) culture format. I want to convert this value into decimal and that too also in English (ed-US) format in c#, like "2,000.65".

Summary:-

I have a string value : "2.000,65"

Now wanted to convert this value into decimal en-US (US English) format as : 2,000.65 in c#

Hope, now its clear to understand question.

I have tried various option, but not able to achieve it.

Can you please help me out ?

Thanks.

Herin

Herin
  • 704
  • 3
  • 18
  • 34

2 Answers2

1
decimal money = decimal.Parse("2.000,65", new CultureInfo("de-DE"));
string result = money.ToString("N2", new CultureInfo("en-US")); 

If you want to show the dollar sign you can use "C" instead of "N2".

Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
  • Hi Tim, it looks good, but the value after decimal point is not coming in english (en-US) culture after converting from de-DE. So here in ed-US format it showing 2,000 instead of 2,000.65. What to do to get decimal value also ? – Herin Jun 03 '16 at 04:00
  • What is "ed-US"? Have you tried my code? It works as expected. – Tim Schmelter Jun 03 '16 at 09:30
  • Sorry, not ed-US, its en-US. And I have tried your code, its working, but the value of after decimal places is not coming. So here in my case it showing value 2000.00 instead of 2,000.65. – Herin Jun 03 '16 at 10:49
  • @Herin: i still don't understand. My code works as expected with the value `"2.000,65"` the result is `"2,000.65"`. So what code are you using or where are you outputting the value? Maybe it's just a display issue. – Tim Schmelter Jun 03 '16 at 10:59
0
string stringValue = "2.000,65";
var decimalValue = decimal.Parse(stringValue, new CultureInfo("de-DE"));
var decimnalUsValue = decimalValue.ToString("N2", new CultureInfo("en-US"));
lordkain
  • 3,061
  • 1
  • 13
  • 18