I have a situation where I need to convert numbers into scientific notation as needed. For this I am using the following:
var teste;
if (dataPoint[1].toString().includes('e')) {
var casas = dataPoint[1].toFixed(16).split(".")[1].match(/^[0]+([1-9])/)[0].length;
teste = dataPoint[1].toFixed(casas);
yValue = parseFloat(dataPoint[1]).toFixed(casas);
} else {
yValue = dataPoint[1];
}
However, toFixed() returns a string. I have already tried several solutions here on the internet but none of them work in my case.
I have already tried the following:
Number(yValue)
+yValue
and this only transforms the number already converted to scientific notation again, but I need to transform it into a number and keep it as a decimal number. For example 0.000000005 , I need to receive this as a number without js converting it to scientific notation again or to a string.
Marcos Nobrega is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.