/** * Convert the value from the current instance's unit to the unit passed. * * @param Unit $unit The unit to convert to * * @return float */ protected function convertValueToUnit(Unit $unit) { // 5kg converted to g will go 5 * 1000 = 5000; 5000 / 1 = 5000g // 500g converted to kg will go 500 * 1 = 500; 500 / 1000 = 0.5kg // Convert the value to the base unit $value = $this->value * $this->unit->value(); //Convert the base value to the new unit return $value / $unit->value(); }