Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

themojilla/v-num

Repository files navigation

npm version

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">
 {{ 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>
 <v-num
 #="{ number }"
 :value="17.5678 / 100"
 number-style="percent"
 maximum-fraction-digits="2"
 sign-display="always"
 >
 {{ number }}
 </nv-um>
</template>
<script setup>
import VNum from "v3-num";
</script>

Output:

+17.57%

For more example checkout the Intel.numberFormat documentations.

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

AltStyle によって変換されたページ (->オリジナル) /