Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion ChartJS.Helpers.MVC/ToJSON.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
Expand Down Expand Up @@ -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();
Expand Down