Meta Engineer?

This is available as Math\round in the 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


$round1 = Math\round(8.65);
echo "8.65 rounded to default precision 0 yields $round1 \n";

$round2 = Math\round(8.65, 1);
echo "8.65 rounded to precision 1 yields $round2 \n";

$round3 = Math\round(8.65, -1);
echo "8.65 rounded to precision -1 yields $round3 \n";