Set up dot instead of comma in numeric values

C#XmlTostringNumericCulture

C# Problem Overview


I have new XmlDocument object, i.g. xml is created during my program...

I want all numeric values in created xml was with dot symbol instead of comma by default.

Can I do something to declare it once, not to parse every decimal value?

I.e. To set up this dot instead of comma somewhere in the beginning and don't worry about this till the end?

C# Solutions


Solution 1 - C#

Try this:

System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
customCulture.NumberFormat.NumberDecimalSeparator = ".";

System.Threading.Thread.CurrentThread.CurrentCulture = customCulture;

Solution 2 - C#

You can use value.ToString(CultureInfo.InvariantCulture) to convert your numeric values to strings. Or you can globally change the current culture to a culture that uses the dot as the decimal separator:

Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US");

Solution 3 - C#

Use Decimal.ToString(..) with System.Globalization.CultureInfo.InvariantCulture like a paramater applied.

or if you want to do it globaly, use

CurrentCulture to set to always Invariant one, by using Applicaton.CurrentCulture property.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKsiceView Question on Stackoverflow
Solution 1 - C#bangView Answer on Stackoverflow
Solution 2 - C#Thomas LevesqueView Answer on Stackoverflow
Solution 3 - C#TigranView Answer on Stackoverflow