numeral 数字格式化
函数名 | 描述 | 类型 | 参数 | 返回值 |
---|---|---|---|---|
numberFormat | 数字格式化,默认2位小数 | (val:number,format:string)=> number | val:数值,format:小数位数 | number |
toFixed | 保留小数点,默认2位 | (val:number,format:string, flag:boolean)=> number | (数值val , 小数位数format ,是否四舍五入round ) | number |
numeral | 文档 | - | - | - |
示例
函数名 | 例子 | 返回值 |
---|---|---|
numberFormat | numberFormat(123.456) | 123.46 |
numberFormat | numberFormat(123.444) | 123.44 |
numberFormat | numberFormat(124.123, '0.0') | 124.1 |
numberFormat | numberFormat(124.123, '0.00') | 124.12 |
toFixed | toFixed(12.166, 2, true) | 12.17 |
toFixed | toFixed(12.166, 2, false) | 12.16 |
<template>
<div>
<config-table title="数字格式化例子" :list="list"></config-table>
</div>
</template>
<script setup lang="ts">
import { numberFormat, toFixed } from '@vtj/utils';
import ConfigTable from '$/components/configTable.vue';
const list = [
{
name: 'numberFormat',
example: 'numberFormat(123.456)',
return: numberFormat(123.456)
},
{
name: 'numberFormat',
example: 'numberFormat(123.444)',
return: numberFormat(123.444)
},
{
name: 'numberFormat',
example: "numberFormat(124.123, '0.0')",
return: numberFormat(124.123, '0.0')
},
{
name: 'numberFormat',
example: "numberFormat(124.123, '0.00')",
return: numberFormat(124.123, '0.00')
},
{
name: 'toFixed',
example: 'toFixed(12.166, 2, true)',
return: toFixed(12.166, 2, true)
},
{
name: 'toFixed',
example: 'toFixed(12.166, 2, false)',
return: toFixed(12.166, 2, false)
}
];
</script>