Search code examples
c#doublestringbuilder

Save double with dot format using StringBuilder


stringBuilder.Append(doubleVariable.ToString());

In my case it will write it as for example 0,15 and I would definitely prefer 0.15.

I did not find any direct answer to that, I bet it can be applied somehow to ToString().


Solution

  • As discussed here the issue is indeed born in Double.ToString(), however it is quite easy to apply formatting to get your period

    value.ToString("0.00", System.Globalization.CultureInfo.InvariantCulture)