Options
All
  • Public
  • Public/Protected
  • All
Menu

Namespace formatters

Provides functionality to control text output.

// esm
import { formatters } from '@paychex/core';

// cjs
const { formatters } = require('@paychex/core');

// iife
const { formatters } = window['@paychex/core'];

// amd
require(['@paychex/core'], function({ formatters }) { ... });
define(['@paychex/core'], function({ formatters }) { ... });
example
// defaults to English number formatting and USD currency
const format = formatters.create();
format.toNumber(-12345.67890); // '-12,345.679'
format.toCurrency(-12345.67890); // '-$12,345.68'
example
// specify US region of English
const format = formatters.create({ locale: 'en-US' });
format.toNumber(-12345.67890); // '-12,345.679'
format.toCurrency(-12345.67890); // '-$12,345.68'
example
// British English number formatting and Pound Sterling currency
const format = formatters.create({
locale: 'en-GB',
numberOptions: {
notation: 'scientific',
maximumFractionDigits: 5,
},
currencyOptions: {
currency: 'GBP',
currencySign: 'accounting',
},
});
format.toNumber(-12345.67890); // '-1.23457E4'
format.toCurrency(-12345.67890); // '(£12,345.68)'

Index

Type aliases

DateRepresentation: number | string | Date

Functions

  • Creates a new Formatter instance with the given options.

    example
    // defaults to English number formatting and USD currency
    const format = formatters.create();
    format.toNumber(-12345.67890); // '-12,345.679'
    format.toCurrency(-12345.67890); // '-$12,345.68'
    example
    // specify US region of English
    const format = formatters.create({ locale: 'en-US' });
    format.toNumber(-12345.67890); // '-12,345.679'
    format.toCurrency(-12345.67890); // '-$12,345.68'
    example
    // British English number formatting and Pound Sterling currency
    const format = formatters.create({
    locale: 'en-GB',
    numberOptions: {
    notation: 'scientific',
    maximumFractionDigits: 5,
    },
    currencyOptions: {
    currency: 'GBP',
    currencySign: 'accounting',
    },
    });
    format.toNumber(-12345.67890); // '-1.23457E4'
    format.toCurrency(-12345.67890); // '(£12,345.68)'

    Parameters

    • options: Partial<FormatterOptions> = {}

      The options to use to create the formatters.

    Returns Formats

    An object with various format methods.