Various classes to handle weighable objects and convert between different mass units. You can either use the Weight object or implement one of the available interfaces.
The Unit
class can measure and convert between several mass units.
Unit | Short name | Constant |
---|---|---|
Miligram | mg | Unit::MILIGRAM |
Gram | g | Unit::GRAM |
Kilogram | kg | Unit::KILOGRAM |
Metric ton | t | Unit::METRICTON |
Carat | c | Unit::CARAT |
Ounce | oz | Unit::OUNCE |
Pund | lb | Unit::POUND |
Stone | st | Unit::STONE |
Grain | grain | Unit::GRAIN |
<?php
echo \Haste\Units\Mass\Unit::convert(
1,
\Haste\Units\Mass\Unit::KILOGRAM,
\Haste\Units\Mass\Unit::POUND
);
Returns
2.20459
<?php
$objScale = new Scale();
// Add one kilogram
$objScale->add(new \Haste\Units\Mass\Weight(1, \Haste\Units\Mass\Unit::KILOGRAM));
// Add 500 gram
$objScale->add(new \Haste\Units\Mass\Weight(5000, \Haste\Units\Mass\Unit::MILIGRAM));
echo $objScale->amountIn(\Haste\Units\Mass\Unit::GRAM);
Returns
1005
Add some more to the scale:
<?php
// Add some stones
$objScale->add(new \Haste\Units\Mass\Weight(3, \Haste\Units\Mass\Unit::STONE));
echo $objScale->amountIn(\Haste\Units\Mass\Unit::POUND);
Returns
2257.60776