From 993a17b8a34d67af3c403529ddf3dccbfbee01e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20J=C3=A4nicke?= Date: Thu, 26 Jul 2018 09:45:04 +0200 Subject: [PATCH] Fix: Correct output of double values in non-english territories --- ChartJS.Helpers.MVC/ToJSON.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ChartJS.Helpers.MVC/ToJSON.cs b/ChartJS.Helpers.MVC/ToJSON.cs index 5707223..18ac1e1 100644 --- a/ChartJS.Helpers.MVC/ToJSON.cs +++ b/ChartJS.Helpers.MVC/ToJSON.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.IO; using System.Linq; using System.Reflection; @@ -75,10 +76,17 @@ public static string ToJSON(object data, int indent = 0) } value = value.TrimEnd(',') + "]"; } - else if (property.PropertyType == typeof(int?) || property.PropertyType == typeof(double?)) + else if (property.PropertyType == typeof(int?)) { value = property.GetValue(data).ToString(); } + else if (property.PropertyType == typeof(double?)) + { + var doubleValue = property.GetValue(data) as double?; + value = doubleValue == null + ? property.GetValue(data).ToString() + : ((double) doubleValue).ToString("F1", new CultureInfo("en-US", false)); + } else if (property.PropertyType == typeof(bool?)) { value = property.GetValue(data).ToString();