Vue Currency Formatter

1.2.4 · maintenance · verified Tue Apr 21

vue-money-format is a lightweight Vue component designed for displaying localized currency values, leveraging the browser's native `Intl.NumberFormat` API. Currently at version 1.2.4, its release cadence appears to be infrequent, with the last known activity around 2020. A key differentiator is its flexibility in handling currency values, supporting both standard super-unit representations (e.g., $100.00) and subunit-based integer storage (e.g., 10000 cents), which aligns with patterns found in libraries like Ruby Money gems to avoid floating-point inaccuracies. It offers configurable localization via BCP 47 language tags and currency symbols via ISO 4217 codes, and includes options to suppress subunit display with automatic rounding. The component boasts no external dependencies beyond Vue itself, making it a lean solution focused solely on currency presentation.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates `vue-money-format`'s core features: subunit/full unit input, locale/currency codes, hiding subunits with rounding, custom `subunits-to-units` conversion, and interactive input with `v-model.number`.

<template>
  <div id="app-container">
    <h2>Vue Money Format Examples</h2>

    <p><strong>Example 1: USD Cents (12345 -> $123.45)</strong></p>
    <money-format
      :value="amountCentsUSD"
      locale="en-US"
      currency-code="USD"
      :subunits-value="true"
    ></money-format>

    <p><strong>Example 2: EUR Full Units (123.45 -> 123,45 €)</strong></p>
    <money-format
      :value="amountFullUnitsEUR"
      locale="de-DE"
      currency-code="EUR"
      :subunits-value="false"
    ></money-format>

    <p><strong>Example 3: GBP Cents, Hidden Subunits (12389 -> £124)</strong></p>
    <money-format
      :value="amountCentsGBP"
      locale="en-GB"
      currency-code="GBP"
      :subunits-value="true"
      :hide-subunits="true"
    ></money-format>

    <p><strong>Example 4: JPY with Subunits-to-Units (500000 -> ¥5,000)</strong></p>
    <p class="note">JPY officially has 0 minor units. This demonstrates custom subunits conversion.</p>
    <money-format
      :value="amountCentsJPY"
      locale="ja-JP"
      currency-code="JPY"
      :subunits-value="true"
      :subunits-to-units="100"
    ></money-format>

    <h3>Interactive Input (Enter amount in cents)</h3>
    <input type="number" v-model.number="interactiveAmount" placeholder="e.g., 99999" />
    <p>Formatted in AUD:</p>
    <money-format
      :value="interactiveAmount"
      locale="en-AU"
      currency-code="AUD"
      :subunits-value="true"
    ></money-format>
  </div>
</template>

<script>
  import MoneyFormat from 'vue-money-format'; // Assumes module resolution via build tool

  export default {
    components: {
      MoneyFormat
    },
    data() {
      return {
        amountCentsUSD: 12345, // Represents $123.45
        amountFullUnitsEUR: 123.45, // Represents 123.45 €
        amountCentsGBP: 12389, // Represents £123.89, will round to £124
        amountCentsJPY: 500000, // Represents ¥5000.00 if subunits-to-units is 100
        interactiveAmount: null
      };
    },
    mounted() {
        this.interactiveAmount = 78950; // Set initial value for interactive input
    }
  };
</script>

view raw JSON →