Formats a number based on the locale and options.
formatNumber(value, options?)
value
- number - Number to be formatted
options?
- object - Formatting options
import { useGlobalize } from 'react-native-globalize';
const ExampleComponent = () => {
const { formatNumber } = useGlobalize();
formatNumber(100000);
// 100,000
};
Type |
Required |
Default |
Description |
string |
No |
none |
Use compact number format. Possible values: short , long . |
formatNumber(100000, { compact: 'short' });
// 100K
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
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
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
Type |
Required |
Default |
Description |
number |
No |
none |
Override minimum integer digits. Numbers will be padded if needed. |
formatNumber(10.45, { minimumIntegerDigits: 3 });
// 010.45
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
Type |
Required |
Default |
Description |
string |
No |
round |
Specify rounding behavior. Possible values: ceil , floor , round , truncate . |
formatNumber(10.45, { maximumFractionDigits: 0, round: 'ceil' });
// 11
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%
Type |
Required |
Default |
Description |
boolean |
No |
true |
Whether to use grouping separator. |
formatNumber(100000, { useGrouping: false });
// 100000