You are here

protected function Fraction::bcRound in Fraction 2.x

Same name and namespace in other branches
  1. 8 src/Fraction.php \Drupal\fraction\Fraction::bcRound()

BCMath decimal rounding function.

Parameters

$value: The value to round.

int $precision: The desired decimal precision.

Return value

string Returns a rounded decimal value, as a PHP string.

1 call to Fraction::bcRound()
Fraction::toDecimal in src/Fraction.php
Calculates the decimal equivalent of the fraction.

File

src/Fraction.php, line 397

Class

Fraction
A simple class for representing and acting upon a fraction.

Namespace

Drupal\fraction

Code

protected function bcRound($value, $precision) {
  if ($value[0] != '-') {
    return bcadd($value, '0.' . str_repeat('0', $precision) . '5', $precision);
  }
  return bcsub($value, '0.' . str_repeat('0', $precision) . '5', $precision);
}