roundPad()
将数值四舍五入到指定的十进制长度,必要时用零填充,并返回结果作为字符串,或者创建一个带有预定义decimalLength参数的四舍五入和填充Function。
const roundedPaddedValue = utils.roundPad(value, decimalLength);
const roundPadderFunction = utils.roundPad(decimalLength);
参数
| 名称 | 接受 |
|---|---|
| value (可选) | Number / String |
| decimalLength | 数字 |
返回
如果提供了值,则返回一个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>