roundPad()
将数值四舍五入到指定的小数位长度,如果需要则补零,并将结果作为字符串返回,或者创建一个具有预定义 decimalLength 参数的四舍五入和补零Function。
const roundedPaddedValue = utils.roundPad(value, decimalLength);
const roundPadderFunction = utils.roundPad(decimalLength);
参数
| 名称 | 接受 |
|---|---|
| value (opt) | Number / String |
| decimalLength | Number |
返回
如果提供了值,则为String,否则为一个 可链式调用的工具 Function,用于将数字四舍五入并填充到指定的小数位长度:
const roundPadTo2Decimals = utils.roundPad(2);
roundPadTo2Decimals(90.12345); // '90.12'
roundPadTo2Decimals(120); // '120.00'
roundPadTo2Decimals(15.9); // '15.90'
const snapAndRoundPad = utils.snap(50).roundPad(2); // Snap to nearest 50 then roundPad to 2 decimal places
snapAndRoundPad(123.456); // '100.00'
snapAndRoundPad(175.789); // '200.00' roundPad() 代码示例
import { animate, utils } from 'animejs';
animate('.value', {
innerHTML: '8.1',
modifier: utils.roundPad(3),
duration: 10000,
ease: 'linear',
});
<div class="large row">
<pre class="large log row">
<span class="value lcd">0.000</span>
</pre>
</div>