Skip to content

Latest commit

 

History

History
136 lines (99 loc) · 3.69 KB

formatNumber.md

File metadata and controls

136 lines (99 loc) · 3.69 KB

formatNumber

Formats a number based on the locale and options.

formatNumber(value, options?)

Arguments

  • value - number - Number to be formatted
  • options? - object - Formatting options

Example

import { useGlobalize } from 'react-native-globalize';

const ExampleComponent = () => {
  const { formatNumber } = useGlobalize();

  formatNumber(100000);
  // 100,000
};

Options

compact

Type Required Default Description
string No none Use compact number format. Possible values: short, long.
formatNumber(100000, { compact: 'short' });
// 100K

maximumFractionDigits

Type Required Default Description
number No none Override maximum fraction digits. Numbers will be rounded if needed based on round option.
formatNumber(10.45, { maximumFractionDigits: 0 });
// 10

maximumSignificantDigits

Type Required Default Description
number No none Override maximum significant (integer + fraction) digits. Numbers will be rounded if needed based on round option. Must also specify minimumSignificantDigits.
formatNumber(10.45, { minimumSignificantDigits: 1, maximumSignificantDigits: 3 });
// 10.5

minimumFractionDigits

Type Required Default Description
number No none Override minimum fraction digits. Numbers will be rounded based on round option or padded if needed.
formatNumber(10.45, { minimumFractionDigits: 4 });
// 10.4500

minimumIntegerDigits

Type Required Default Description
number No none Override minimum integer digits. Numbers will be padded if needed.
formatNumber(10.45, { minimumIntegerDigits: 3 });
// 010.45

minimumSignificantDigits

Type Required Default Description
number No none Override minimum significant (integer + fraction) digits. Numbers will be padded if needed. Must also specify maximumSignificantDigits.
formatNumber(10.45, { minimumSignificantDigits: 6, maximumSignificantDigits: 8 });
// 10.4500

round

Type Required Default Description
string No round Specify rounding behavior. Possible values: ceil, floor, round, truncate.
formatNumber(10.45, { maximumFractionDigits: 0, round: 'ceil' });
// 11

style

Type Required Default Description
string No decimal Change display style. Possible values: decimal, percent.
formatNumber(0.45, { style: 'decimal' });
// 0.45
formatNumber(0.45, { style: 'percent' });
// 45%

useGrouping

Type Required Default Description
boolean No true Whether to use grouping separator.
formatNumber(100000, { useGrouping: false });
// 100000