In Javascript ,how to represent 1.00 as a number in a JSON object? -


all want create json string :

'{  "a" : 1.00 }' 

i have tried

var n = 1.00; var x = { : n }; console.log(json.stringify(x)); // gives {"a":1}  var n = 1.00; var x = { : n.tofixed(2) }; console.log(json.stringify(x)); // gives {"a":"1.00"}  var x = { x : 1.00 };     x = json.stringify(x , function(key,val ){     if( typeof val === "number")         return val.tofixed(2);      return val; });  console.log(x); // gives {"x":"1.00"} 

is possible represent '{ "a" : 1.00 }' json string in javascript ? if yes, how can ?

a number in json doesn't have specific precision. number represented shortest notation needed reproduce it.

the value 1.00 same value 1, how represented in json.

if want represent number in 1.00 format, can't store number, need use string.

the string '{"x":1.00}' valid json, has same meaning '{"x":1}'.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -