Requires the Hack Standard Library to be installed.
Facebook Engineer?

This function is available as Str\format_number() in Facebook's www repository.

Returns a string representation of the given number with grouped thousands

namespace HH\Lib\Str;

function format_number(
  num $number,
  int $decimals = 0,
  string $decimal_point = '.',
  string $thousands_separator = ',',
): string;

If $decimals is provided, the string will contain that many decimal places. The optional $decimal_point and $thousands_separator arguments define the strings used for decimals and commas, respectively.


  • num $number
  • int $decimals = 0
  • string $decimal_point = '.'
  • string $thousands_separator = ','


  • string