How can I use JSON.stringify to convert a negative zero into a string (-0)? It appears that JSON.stringify converts a negative zero into a string representing a positive one. Any idea for a nice workaround?
var jsn = {
negative: -0
};
isNegative(jsn.negative) ? document.write("negative") : document.write("positive");
var jsonString = JSON.stringify(jsn),
anotherJSON = JSON.parse(jsonString);
isNegative(anotherJSON.negative) ? document.write("negative") : document.write("positive");
function isNegative(a)
{
if (0 !== a)
{
return !1;
}
var b = Object.freeze(
{
z: -0
});
try
{
Object.defineProperty(b, "z",
{
value: a
});
}
catch (c)
{
return !1;
}
return !0;
}