Neos\Eel\Helper\MathHelper::round PHP Method

round() public method

The precision defines the number of digits after the decimal point. Negative values are also supported (-1 rounds to full 10ths).
public round ( float $subject, integer $precision ) : float
$subject float The value to round
$precision integer The precision (digits after decimal point) to use, defaults to 0
return float The rounded value
    public function round($subject, $precision = 0)
    {
        if (!is_numeric($subject)) {
            return NAN;
        }
        $subject = floatval($subject);
        if ($precision != null && !is_int($precision)) {
            return NAN;
        }
        return round($subject, $precision);
    }

Usage Example

 /**
  * @test
  * @dataProvider roundExamples
  */
 public function roundWorks($value, $precision, $expected)
 {
     $helper = new MathHelper();
     $result = $helper->round($value, $precision);
     if ($expected === static::NAN) {
         $this->assertTrue(is_nan($result), 'Expected NAN');
     } else {
         $this->assertEquals($expected, $result, 'Rounded value did not match', 0.0001);
     }
 }