Skip to content

Instantly share code, notes, and snippets.

@liabru
liabru / json-limit-precision.js
Last active May 3, 2023 07:45
Limit precision of floating point numbers in a JSON string in JavaScript
var testObject = {
pi: Math.PI,
e: Math.E,
one: 1,
x: 1.5,
str: "1.2345"
};
var places = 2,
json = JSON.stringify(testObject, function(key, value) {