I have a problem concatenating a json.
I'm doing:
jsonb = jsonb.concat(1.200);
Then When I use the jsonb I see "1.2" but not "1.200" I need the number with zeros, how can I do it?
I have a problem concatenating a json.
I'm doing:
jsonb = jsonb.concat(1.200);
Then When I use the jsonb I see "1.2" but not "1.200" I need the number with zeros, how can I do it?
1.200 is not a number that most systems want to work with, so they would truncate it to 1.2. As others have stated, you could use the toFixed method to fix this, or simply make this value a string. Since you don't need the zeros for math, it's clear you want them to be visual, so you could just make it a string.
jsonb = jsonb.concat('1.200');
You can use toFixed
on a number value, but as others have pointed out, numbers by themselves have no trailing zeroes, this function returns a string.
console.log(1.200); // 1.2, no trailing zeroes
console.log(1.2.toFixed(3)); // 1.200, trailing zeroes
let someValue = 1.25;
console.log(someValue.toFixed(0)); // 1
console.log(someValue.toFixed(1)); // 1.3
console.log(someValue.toFixed(2)); // 1.25
console.log(someValue.toFixed(3)); // 1.250
let val = someValue.toFixed(2);
console.log(typeof someValue); // number
console.log(typeof val); // string