Skip to content

numeral 数字格式化

函数名描述类型参数返回值
numberFormat数字格式化,默认2位小数(val:number,format:string)=> numberval:数值,format:小数位数number
toFixed保留小数点,默认2位(val:number,format:string, flag:boolean)=> number(数值val, 小数位数format,是否四舍五入round)number
numeral文档---

示例

数字格式化例子
函数名例子返回值
numberFormatnumberFormat(123.456)123.46
numberFormatnumberFormat(123.444)123.44
numberFormatnumberFormat(124.123, '0.0')124.1
numberFormatnumberFormat(124.123, '0.00')124.12
toFixedtoFixed(12.166, 2, true)12.17
toFixedtoFixed(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>

Released under the MIT License.