-4

Good morning,

if I convert a Decimal variable to String it replaces "." with "," is it possible to prevent this from happening?

  • 1
    Have you read the documentation? https://learn.microsoft.com/en-us/dotnet/api/system.decimal.tostring?view=netcore-3.1 – UnholySheep Sep 16 '20 at 14:00
  • Does this answer your question? [How to change symbol for decimal point in double.ToString()?](https://stackoverflow.com/questions/3135569/how-to-change-symbol-for-decimal-point-in-double-tostring) – Dinac23 Sep 16 '20 at 14:00
  • " it replaces "." with "," " that depends on the culture of your machine if you haven't specified it explicitly inside your code. That means that the conversion can lead to different results when your code runs on a different machine – Mong Zhu Sep 16 '20 at 14:15

1 Answers1

2

Looks like you are hitting a culture formatting issue. The Microsoft documentation for Decimal.ToString() has the solution you need, but for quickness you can use:

value.ToString(CultureInfo.InvariantCulture)

or replace CultureInfo.InvariantCulture with

CultureInfo.CreateSpecificCulture("insert culture short code")
Colin Wiseman
  • 848
  • 6
  • 10
  • it is not possible to do it globally without having to specify it to each string? – Francesco Buscicchio Sep 16 '20 at 14:08
  • @FrancescoBuscicchio - yes it is. Now you need to look into Globalization in the web.config. That's a whole topic in itself, so enjoy all the reading. Best way to learn ;-) – Colin Wiseman Sep 16 '20 at 14:11
  • 1
    @ColinWiseman :D it is difficult to avoid devloping into a word picker over time here. I'll delete my comment ;) – Mong Zhu Sep 16 '20 at 14:30