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

This function is available as Math\round() in Facebook's www repository.

Returns the given number rounded to the specified precision

namespace HH\Lib\Math;

function round(
  num $val,
  int $precision = 0,
): float;

A positive precision rounds to the nearest decimal place whereas a negative precision rounds to the nearest power of ten. For example, a precision of 1 rounds to the nearest tenth whereas a precision of -1 rounds to the nearest ten.


  • num $val
  • int $precision = 0


  • float