Skip to content

Latest commit

 

History

History
66 lines (46 loc) · 1.74 KB

Mass.md

File metadata and controls

66 lines (46 loc) · 1.74 KB

Haste Mass Units

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.

Supported mass units

The Unit class can measure and convert between several mass units.

UnitShort nameConstant
MiligrammgUnit::MILIGRAM
GramgUnit::GRAM
KilogramkgUnit::KILOGRAM
Metric tontUnit::METRICTON
CaratcUnit::CARAT
OunceozUnit::OUNCE
PundlbUnit::POUND
StonestUnit::STONE
GraingrainUnit::GRAIN

Examples

Convert a weight

<?php

echo \Haste\Units\Mass\Unit::convert(
	1,
	\Haste\Units\Mass\Unit::KILOGRAM,
	\Haste\Units\Mass\Unit::POUND
);

Returns 2.20459

Measure weight of multiple object

<?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