# HG changeset patch # User cin # Date 2015-03-04 00:10:38 # Node ID 2100965eb97f5c92f8731632172780f340e26302 # Parent 0fa293bb1351e448bde0470e9175c483ecc68993 fixed JSONWriter handling Infinity, NaN and locale aware number formatting diff --git a/Implab/JSON/JSONWriter.cs b/Implab/JSON/JSONWriter.cs --- a/Implab/JSON/JSONWriter.cs +++ b/Implab/JSON/JSONWriter.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Globalization; namespace Implab.JSON { public class JSONWriter { @@ -35,7 +36,6 @@ namespace Implab.JSON { public JSONWriter(TextWriter writer) { Safe.ArgumentNotNull(writer, "writer"); - m_writer = writer; } @@ -262,7 +262,14 @@ namespace Implab.JSON { } void Write(double value) { - m_writer.Write(value); + if (double.IsNaN(value)) + Write("NaN"); + else if (double.IsNegativeInfinity(value)) + Write("-Infinity"); + else if (double.IsPositiveInfinity(value)) + Write("Infinity"); + else + m_writer.Write(value.ToString(CultureInfo.InvariantCulture)); } void OperationNotApplicable(string opName) {