roundPad() V4
将值四舍五入到指定的小数位数,如果需要,用零填充,并将结果作为字符串返回,或者创建一个具有预定义 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>