Socket
Socket
Sign inDemoInstall

@formatjs/intl-unified-numberformat

Package Overview
Dependencies
0
Maintainers
2
Versions
43
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@formatjs/intl-unified-numberformat


Version published
Maintainers
2
Created

Package description

What is @formatjs/intl-unified-numberformat?

@formatjs/intl-unified-numberformat is a polyfill for the ECMAScript Internationalization API's Unified NumberFormat, which provides a way to format numbers in a locale-sensitive manner. This package is particularly useful for applications that need to support multiple locales and require consistent number formatting across different environments.

What are @formatjs/intl-unified-numberformat's main functionalities?

Basic Number Formatting

This feature allows you to format numbers according to the locale specified. In this example, the number 1234567.89 is formatted according to the 'en-US' locale.

const UnifiedNumberFormat = require('@formatjs/intl-unified-numberformat');
const formatter = new UnifiedNumberFormat('en-US');
console.log(formatter.format(1234567.89)); // Output: 1,234,567.89

Currency Formatting

This feature allows you to format numbers as currency. In this example, the number 1234567.89 is formatted as USD currency according to the 'en-US' locale.

const UnifiedNumberFormat = require('@formatjs/intl-unified-numberformat');
const formatter = new UnifiedNumberFormat('en-US', { style: 'currency', currency: 'USD' });
console.log(formatter.format(1234567.89)); // Output: $1,234,567.89

Percent Formatting

This feature allows you to format numbers as percentages. In this example, the number 0.1234 is formatted as a percentage according to the 'en-US' locale.

const UnifiedNumberFormat = require('@formatjs/intl-unified-numberformat');
const formatter = new UnifiedNumberFormat('en-US', { style: 'percent' });
console.log(formatter.format(0.1234)); // Output: 12%

Unit Formatting

This feature allows you to format numbers with units. In this example, the number 60 is formatted as miles per hour according to the 'en-US' locale.

const UnifiedNumberFormat = require('@formatjs/intl-unified-numberformat');
const formatter = new UnifiedNumberFormat('en-US', { style: 'unit', unit: 'mile-per-hour' });
console.log(formatter.format(60)); // Output: 60 mph

Other packages similar to @formatjs/intl-unified-numberformat

Readme

Source

intl-unified-numberformat

A ponyfill for intl-unified-numberformat. This wraps Intl.NumberFormat and has the exact same APIs.

Installation

npm install @formatjs/intl-unified-numberformat

Requirements

This package requires the following capabilities:

Usage

To use the ponyfill, import it along with its data:

import {UnifiedNumberFormat} from '@formatjs/intl-unified-numberformat'
UnifiedNumberFormat.__addUnitLocaleData(
  'bit',
  ...require('../dist/locale-data/bit/zh') // locale-data for zh for unit `bit`
);
UnifiedNumberFormat.__addUnitLocaleData(
  'bit',
  ...require('../dist/locale-data/bit/en')  // locale-data for zh for unit `bit`
);

new UnifiedNumberFormat('zh', {
    style: 'unit',
    unit: 'bit',
    unitDisplay: 'long'
}).format(1000) // 1,000比特

Keywords

FAQs

Last updated on 16 Aug 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc