- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有这个代码:
10.00000001.toLocaleString('en-GB', {useGrouping: true, minimumFractionDigits: 2})
我希望它返回'10.00000001'
,但我得到的是10.00
。当我更改最小值时,准确度也会相应变化。
最小值就像最大值一样。
设置maximumFractionDigits
不会改变任何东西。它被完全忽略。
我使用节点 8.1.4 和 FF Quantum 对此进行了测试。
知道为什么 toLocaleString
表现得如此奇怪吗?
最佳答案
根据文档https://www.jsman.net/manual/Standard-Global-Objects/Number/toLocaleString ,最小值是您想要的小数位数。下面两个例子可以让大家清楚地理解
var n = 10.00000001;
var x;
// It will give 8 decimal point because min is 0 (i.e. Atleast it should have one decimal point) and max it can have till 8
x = n.toLocaleString('en-GB', {useGrouping: true, minimumFractionDigits: 0, maximumFractionDigits: n.toString().split('.')[1].length});
console.log(x);
// If you put value 2.301 it gives 2.3 since it omits 0 in 2.30 (i.e.
n = 2.311;
// It will give 1 decimal point because min to max is 1
x = n.toLocaleString('en-GB', {useGrouping: true, minimumFractionDigits: 1, maximumFractionDigits: 2});
console.log(x);
// It will give 1 decimal point eventhough we didn't have decimal points
n = 2;
x = n.toLocaleString('en-GB', {useGrouping: true, minimumFractionDigits: 1});
console.log(x);
关于javascript - Number.toLocaleString(),minimumFractionDigits 的作用类似于 max,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47742977/
我想按照以下规则格式化和显示 Double: If there are more than 2 fractional digits, display it as 6 significant figur
我尝试使用 toLocaleString() 来格式化我的号码,但它做不到。 var number = 123.456; console.log(number.toLocaleString('en-G
我有这个代码: 10.00000001.toLocaleString('en-GB', {useGrouping: true, minimumFractionDigits: 2}) 我希望它返回'10
我正在尝试向 Chart.js 图表的 X 轴添加标题,但是当我将标题属性放在 x 轴上时,出现错误 Uncaught RangeError: minimumFractionDigits value
我是一名优秀的程序员,十分优秀!