I have the weight grabbed from an xml as 0.800, I want to convert it to 000008. This Eg. 003456 is 345.6 kilograms shows how it is to be represented for heavier weights, could someone give me a heads up as to where I could start with this one?
thanks!
EDIT: I have the solution but does anyone know why it cuts off the last digit? See below:
XML:
<GROSSWEIGHT>345.800</GROSSWEIGHT>
PHP:
$LINE_WEIGHT = ($shipment->COLLO->GROSSWEIGHT*10); // 6 CHARS
sprintf("%06s", $LINE_WEIGHT)
// output 003450
EDIT: If i follow this, it works:
echo str_pad(0.800*10, 6, "0", STR_PAD_LEFT);
// output 000008
AS SOON as I include xml data:
echo $shipment->COLLO->GROSSWEIGHT; // 345.800
echo str_pad($shipment->COLLO->GROSSWEIGHT*10, 6, "0", STR_PAD_LEFT);
// output 003450
Please see pic below: