Skip to content

number

The module number is a function that formats numbers

This module uses the native api Intl.NumberFormat from browsers

formatted value: 69.00
vue
<template>
  <MazInput v-model="numberValue" type="number" />

  <div
    style="padding: 16px; margin-top: 16px; background-color: var(--maz-color-bg-lighter);"
  >
    {{ numberFormatted }}
  </div>
</template>

<script lang="ts" setup>
  import { number } from 'maz-ui'
  import { ref, computed } from 'vue'

  const numberValue = ref(69)

  const numberFormatted = computed(() =>
    number(numberValue.value, 'en-US'),
  )
</script>

Options

All options from Intl.NumberFormat are available

Default options

ts
const DEFAULT_OPTIONS: Intl.NumberFormatOptions = {
  minimumFractionDigits: 2,
}