Skip to content
0

katanakit-js / useFormatCurrency

Function: useFormatCurrency() ​

ts
function useFormatCurrency(options): string;

Defined in: src/core/services/formatter.service.ts:108

Pure: formats an amount as currency.

taxes accepts either a percentage (21 → 21%) or a decimal fraction (0.21 → 21%). Values > 1 are treated as percentages; values in (0, 1] as fractions. Prefer an explicit fraction when you need a rate ≤ 1%.

Parameters ​

ParameterTypeDescription
options{ amount: number; currency?: | "EUR" | "USD" | "GBP" | "JPY" | "CAD" | "MXN" | "CHF" | "AUD" | "BRL" | "CNY" | "ARS" | "COP" | "CLP"; locale?: "en" | "es" | "fr" | "de" | "it" | "pt" | "ja" | "zh"; taxes?: number; }Currency formatting options.
options.amountnumber-
options.currency?| "EUR" | "USD" | "GBP" | "JPY" | "CAD" | "MXN" | "CHF" | "AUD" | "BRL" | "CNY" | "ARS" | "COP" | "CLP"-
options.locale?"en" | "es" | "fr" | "de" | "it" | "pt" | "ja" | "zh"-
options.taxes?numberTax rate: percentage when > 1 (e.g. 21 → 21%), or decimal fraction when in (0, 1] (e.g. 0.21 → 21%). Prefer a fraction for rates ≤ 1%.

Returns ​

string

The formatted currency string.

Example ​

ts
import { useFormatCurrency } from "katanakit-js";

useFormatCurrency({ amount: 100, currency: "USD" }); // "$100.00"
useFormatCurrency({ amount: 100, taxes: 21 }); // "$121.00"
useFormatCurrency({ amount: 100, taxes: 0.21, locale: "es" }); // "121,00 €"

Released under the MIT License.