Skip to content

Commit

Permalink
Use culture independent ToString for converting doubles to string
Browse files Browse the repository at this point in the history
  • Loading branch information
vvoland committed May 29, 2017
1 parent 94a0c59 commit 381fe65
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions GnuPlot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.IO;
using System.Threading;
using System.Linq;
using System.Globalization;

namespace AwokeKnowing.GnuplotCSharp
{
Expand Down Expand Up @@ -374,15 +375,15 @@ public static void SPlot(List<StoredPlot> storedPlots)
public static void WriteData(double[] y, StreamWriter stream, bool flush = true)
{
for (int i = 0; i < y.Length; i++)
stream.WriteLine(y[i].ToString());
stream.WriteLine(y[i].ToString(CultureInfo.InvariantCulture));

if (flush) stream.Flush();
}

public static void WriteData(double[] x, double[] y, StreamWriter stream, bool flush = true)
{
for (int i = 0; i < y.Length; i++)
stream.WriteLine(x[i].ToString() + " " + y[i].ToString());
stream.WriteLine(x[i].ToString(CultureInfo.InvariantCulture) + " " + y[i].ToString(CultureInfo.InvariantCulture));

if (flush) stream.Flush();
}
Expand All @@ -393,7 +394,7 @@ public static void WriteData(int ySize, double[] z, StreamWriter stream, bool fl
{
if (i > 0 && i % ySize == 0)
stream.WriteLine();
stream.WriteLine(z[i].ToString());
stream.WriteLine(z[i].ToString(CultureInfo.InvariantCulture));
}

if (flush) stream.Flush();
Expand All @@ -408,7 +409,7 @@ public static void WriteData(double[,] zz, StreamWriter stream, bool flush = tru
{
line = "";
for (int j = 0; j < n; j++)
line += zz[i, j].ToString() + " ";
line += zz[i, j].ToString(CultureInfo.InvariantCulture) + " ";
stream.WriteLine(line.TrimEnd());
}

Expand All @@ -423,7 +424,8 @@ public static void WriteData(double[] x, double[] y, double[] z, StreamWriter st
{
if (i > 0 && x[i] != x[i - 1])
stream.WriteLine("");
stream.WriteLine(x[i] + " " + y[i] + " " + z[i]);

stream.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0} {1} {2}", x[i], y[i], z[i]));
}

if (flush) stream.Flush();
Expand Down

0 comments on commit 381fe65

Please sign in to comment.