Zum Hauptinhalt springen Seitenleiste
Zum Inhaltsverzeichnis springen

    Format Number

    <pc-format-number> 1.0.0-alpha.1 experimental

    Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

    Formats a number using the specified locale and options.

    Localisation is handled by the browser’s Intl.DateTimeFormat API. No language packs are required.

    <div class="format-number-overview">
        <pc-format-number value="1000"></pc-format-number>
    
        <br /><br />
    
        <pc-input
            label="Number to format"
            type="number"
            value="1000"
            style="max-inline-size: 180px"
        ></pc-input>
    </div>
    
    <script>
        const container = document.querySelector(".format-number-overview");
        const formatter = container.querySelector("pc-format-number");
        const input = container.querySelector("pc-input");
    
        input.addEventListener("pc-input", () => (formatter.value = input.value || 0));
    </script>
    Code Edit

    Demos#

    Percentages#

    To get the value as a percentage, set the type attribute to percent.

    Edit

    Localisation#

    Use the lang attribute to set the number formatting locale.

    Edit

    SI conventions #

    Add the use-si attribute to change the formatting of the component to follow SI conventions.

    This property is experimental and does not work on currencies.

    Edit

    Currency#

    To format a number as a monetary value, set the type attribute to currency and set the currency attribute to the desired ISO 4217 currency code. You should also specify the lang attribute to ensure that the number and currency symbol is formatted correctly for the target locale.

    Edit

    Properties#

    NameDescriptionReflectsDefault
    valueThe number to format.
    Type: number
    0
    typeThe formatting style to use.
    Type: "currency" | "decimal" | "percent"
    "decimal"
    withoutGrouping
    without-grouping
    Turns off grouping separators.
    Type: boolean
    false
    currencyThe ISO 4217 currency code to use when formatting.
    Type: string
    "USD"
    currencyDisplay
    currency-display
    Specifies how to display the currency.
    Type: "symbol" | "narrowSymbol" | "code" | "name"
    "symbol"
    minimumIntegerDigits
    minimum-integer-digits
    The minimum number of integer digits to use. Possible values are 1–21.
    Type: number | undefined
    minimumFractionDigits
    minimum-fraction-digits
    The minimum number of fraction digits to use. Possible values are 0–100.
    Type: number | undefined
    maximumFractionDigits
    maximum-fraction-digits
    The maximum number of fraction digits to use. Possible values are 0–100.
    Type: number | undefined
    minimumSignificantDigits
    minimum-significant-digits
    The minimum number of significant digits to use. Possible values are 1–21.
    Type: number | undefined
    maximumSignificantDigits
    maximum-significant-digits
    The maximum number of significant digits to use,. Possible values are 1–21.
    Type: number | undefined
    useSI
    use-si
    Forces the component to use the SI standard for formatting. This overrides locale‐specific rules.
    Type: boolean
    false
    updateComplete A read‐only promise that resolves when the component has finished updating.

    Learn more about attributes and properties.

    Importing#

    If you’re using the autoloader or the standard loader, you can skip this section. But if you’re cherry picking, you can use any of the following snippets to import this component.

    CDN (script tag) CDN (import) npm (import)

    To manually import this component from the CDN, copy this code snippet and paste it in your HTML.

    <script type="module" src="https://cdn.jsdelivr.net/npm/placer-toolkit@1.0.0-alpha.3/cdn/components/format-number/format-number.js"></script>

    To manually import this component from the CDN, copy this code snippet and paste it in your JavaScript file.

    import "https://cdn.jsdelivr.net/npm/placer-toolkit@1.0.0-alpha.3/cdn/components/format-number/format-number.js";

    To manually import this component from npm, copy this code snippet and paste it in your JavaScript file.

    import "placer-toolkit/dist/components/format-number/format-number.js";

    Wir würden uns freuen, von dir zu hören. Bitte kontaktiere uns bei Fragen oder Anliegen, die du hast.

    Du kannst uns per E‐Mail unter placer.coc.reports+contact@gmail.com erreichen.

    Wir freuen uns darauf, von dir zu hören!

    Alles klar!
    Gefährliche Lande

    Ui! Du bist in die gefährlichen Lande von Placer Toolkit geraten. Version 0 ist veraltet und entspricht nicht den EU‐Datenschutzstandards, einschließlich DSGVO.

    Willst du die neuesten Kräfte, Sicherheit und Compliance? Bleib bei der aktuellen Version von Placer Toolkit!

    Ups! Aufladen!