Skip to content

formatNumber

The module formatNumber is a function that formats numbers with the native api [Intl.NumberFormat](https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat) from browsers and Node.js

This module uses the native api Intl.NumberFormat from browsers

formatted value: 69.00
vue
<script lang="ts" setup>
import { formatNumber } from 'maz-ui'
import { computed, ref } from 'vue'

const numberValue = ref(69)

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

<template>
  <MazInput v-model="numberValue" type="number" />

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

Options

All options from Intl.NumberFormat are available

Default options

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