Skip to main content

formatNumber

Formats a number with the max number of decimal places.

API

function formatNumber(number: number, maxDecimalPlaces: number): string | number;

Usage

import { formatNumber } from '@feedzai/js-utilities';

formatNumber(1200, 1)
//=> "1.2K"

formatNumber(12000, 1)
//=> "12K"

formatNumber(120000, 1)
//=> "120K"

formatNumber(1200000, 1)
//=> "1.2M"

formatNumber(12000000, 1)
//=> "12M"

formatNumber(12000000, 1)
//=> "12M"

formatNumber(1200000000, 1)
//=> "1.2B"

formatNumber(1235442, 1)
//=> "1.2M"

formatNumber(1235442, 3)
//=> "1.235M"

formatNumber(1700, 0)
//=> "2K"

formatNumber(1700, 1)
//=> "1.7K"

formatNumber(17000000, 1)
//=> "17M"

formatNumber(1700000000, 1)
//=> "1.7B"

formatNumber(1710, 1)
//=> "1.7K"

formatNumber(1710, 2)
//=> "1.71K"

formatNumber(174000, 1)
//=> "174K"

formatNumber(174000, 2)
//=> "174K"

formatNumber(3820000, 1)
//=> "3.8M"

formatNumber(388000, 1)
//=> "388K"

formatNumber(388200000, 1)
//=> "388M"

formatNumber(990, 1)
//=> 990

formatNumber(990.567, 2)
//=> 991