How to allow PHP calculation 0 appears if example :
$a = "00001";
$b = "00005";
$total = $a + $b;
Expected result is : 00006
Including and keep 0000
appears.
I tried but the result always : 6
How to allow PHP calculation 0 appears if example :
$a = "00001";
$b = "00005";
$total = $a + $b;
Expected result is : 00006
Including and keep 0000
appears.
I tried but the result always : 6
Just do normal math and then add the zeros back in front at the end:
$a = "00001";
$b = "00005";
$total = $a + $b;
$total = sprintf("%05d", $total );
or
$total = str_pad($total , 5, "0", STR_PAD_LEFT);
You might want to try and prepend the needed 0's
<?php
$total = 6;
$total_padded = sprintf("%05s", $num);
echo $num_padded; // returns 00006
?>
I haven't tested it but it should work :)
I assume that the value is integer so you should use intval. If it is float use floatval
$a = "00001";
$b = "00005";
print intval($a);
print intval($b);
print intval($a)+intval($b);
than add the leading zeros