I receive numbers in scientific notation formats. Then I create trailing zeros with toFixed(), but it converts the return to a string, but I need them as a number. If I use Number(), it reverts to scientific notation.
Look:
if (dataPoint[1].toString().includes('e')) {
var casas = dataPoint[1].toFixed(16).split(".")[1].match(/^[0]+([1-9])/)[0].length;
yValue = parseFloat(dataPoint[1]).toFixed(casas);
} else {
yValue = dataPoint[1];
}
How do I get decimals in number format using toFixed()?
The reason being, any trailing zeroes on a number are just superfluous in floating point numbers. 1000.500 is the same as 1000.5. You can test and verify this with the following code:
var value = 1000.500;
console.log(value); // 1000.5
@martinbean but I receive this as a value: 1.38e-11 , it appears as a number type and I need to treat it as a number even after toFixed(). It seems so simple, but I can't solve it