如何防止很小的数字转换为科学记数法?

rap*_*dko 8 javascript

我必须使用非常小的数字:

var x = 0.00000006;
Run Code Online (Sandbox Code Playgroud)

当我运行console.log(x)时,它显示:

6e-8
Run Code Online (Sandbox Code Playgroud)

我不希望它显示6e-8,我希望它显示0.00000006

后来我需要将它绘制在图表上,所以我无法将其转换为字符串。如何保持它是一个小数字而不将其转换为字符串或科学记数法?

som*_*Guy 3

您可以将其转换为“固定”形状并使其看起来像您想要的那样。例子是:

var number = 6e-8; //this is your number
number = number.toFixed(8) //but since you won't always know how many decimal points you have you can use something like
number = number.toFixed(number.toString().split('-')[1]); //where you split your number, see how many decimals it has and pass that number to .toFixed method
Run Code Online (Sandbox Code Playgroud)