v3-num

A Vue 3 headless component to formatting numbers using Intl.numberFormat.
2,967 3
Install
npm install v3-num
Latest Version:0.1.1
Vue:3
License:MIT
Last Updated:Nov 28, 2021
Links: GitHub  ·  npm
Maintainer: mojilla

A Vue 3 headless component to formatting numbers using Intl.numberFormat.

Warning: the v3-num tend to use Intl.numberFormat API internally. It is made for modern browsers, but if you want to keep things also working for older ones, make sure to polyfill the Intl API

Installation

yarn add v3-num

Usage

Globally

import { createApp } from "vue";
import VNum from "v3-num";

createApp.use(VNum);

Individually

<template>
  <v-num #="{ number }" :value="1000">
    {{ number }}
  </v-num>
</template>

<script setup>
import VNum from "v3-num";
</script>

Examples

Basic decimal formatter.

<template>
  <v-num #="{ number }" :value="1000" round>
    {{ number }}
  </v-num>
</template>

<script setup>
import VNum from "v3-num";
</script>

Output:

1,000

Make the value rounded to the nearest integer.

<template>
  <v-num #="{ number }" :value="1000.555" round>
    {{ number }}
  </v-num>
</template>

<script setup>
import VNum from "v3-num";
</script>

Output:

1,001

Percentage formatting

<template>
  <num
    #="{ number }"
    :value="17.5678 / 100"
    number-style="percent"
    maximum-fraction-digits="2"
    sign-display="always"
  >
    {{ number }}
  </num>
</template>

<script setup>
import VNum from "v3-num";
</script>

Output:

+17.57%

For more example checkout the Intel.numberFormat documentations.

Related Packages

@coders-tm/vue-number-format

Easy formatted numbers, currency and percentage with input/directive mask for Vu...

436,576 122
directix

A comprehensive, easy-to-use, and high-performance Vue custom directives library...

4,127 2
markdown-to-jsx

A very fast and versatile markdown toolchain. AST, React, React Native, SolidJS,...

214,042,213 2,394
@scalar/use-toasts

display toasts in Vue

24,371,992 16,329
@scalar/use-codemirror

CodeMirror for Vue

21,770,238 16,329

Version History

Version Released Vue License
0.1.1 ^3.2.16 MIT