PHP Weight Class helps developers to work with mass units.
1-
$weight = new Weight(300, new Unit('KG'));
echo $weight; // 300 Kg
$wight->getValue() // returns 300
$weight->getUnit() // return Weight/Unit of KG.
2-
$weight = new Weight(15, 'KG');
echo $weight;
shows
300 Kg
$kgs = new Weight(300, new Unit('KG'));
$grams = $kgs->to(UNIT::GRAM);
echo (string) $grams;
shows
300,000.00 g
$tonnes = $kgs->to('tonne');
echo (string) $tonnes;
shows
0.30 Mg