/** * Gets the value of this instance at the specified units. * * @param $units Units, e.g. m/s * @param bool $string True to return as string for higher precision * * @return double|string */ public function units($units, $string = false) { // Explode units list($distUnit, $timeUnit) = static::explUnits($units); // Get and format the distance and time unit values $distVal = $this->dist->unit($distUnit); $timeVal = $this->time->{$timeUnit}; $distVal = number_format($distVal, 99, '.', ''); $timeVal = number_format($timeVal, 99, '.', ''); // Calculate the velocity value $velocity = bcdiv($distVal, $timeVal, 999); $velocity = static::removeTrailingZeros($velocity); // Return either string or double return $string ? $velocity : (double) $velocity; }