Skip to content

Currency Formatting (useCurrencyFormat)

useCurrencyFormat is a Vue composable function used for currency formatting, and it also provides a non-reactive version called formatCurrency.

It helps you easily handle common scenarios such as: amount display, decimal truncation, thousand separators, and currency symbols.

API Source Code: GitHub

Usage

vue
<template>
  {{ display }}
</template>

<script setup>
import { ref } from "vue";
import { useCurrencyFormat } from "see-u-ui";

const amount = ref(1234.567);

const display = useCurrencyFormat(amount, {
  decimals: 2,
  symbol: "¥",
  useGrouping: true,
});
</script>
vue
<script setup>
import { formatCurrency } from "see-u-ui";

formatCurrency(1234.567, {
  decimals: 2,
  symbol: "¥",
});
</script>

Formatting Rules

FeatureDescription
Decimal TruncationNo rounding, e.g., 12.349 → 12.34
Auto Zero-paddingWhen decimals=2 is specified, it fills two decimal places.
Thousand Separatore.g., 1,234,567.89
Symbol PrefixSupports ¥, $, , or any custom string.
Placeholder HandlingDisplays - when the value is null / undefined / ''.

API

useCurrencyFormat(amount, options?)

Reactive Currency Formatting

ParameterTypeDefaultDescription
amount`MaybeRefOrGetter<numberstring>`
optionsCurrencyOptions{}Configuration options
options.decimalsnumber2Decimal places to keep (truncation)
options.symbolstring''Currency symbol
options.placeholderstring'-'Display content for invalid amounts
options.useGroupingbooleantrueWhether to enable thousand separators

Returns: ComputedRef<string>


formatCurrency(value, options?)

Non-reactive Currency Formatting Utility Function

ParameterTypeDefaultDescription
value`numberstring`
optionsCurrencyOptions{}Formatting configuration

Returns: string

Liao ICP No. 2025070134