For invoicing I want to determine if my total amount has an unnecessary cent. e.g. $5.01 or $5.51. If it detects the cent then I run an if statement to remove the cent: minus 0.01
$pieces = explode(".", $TotalAmt);
echo "<br>p1:".$pieces; // piece2
$p1 = $pieces;
$spl1 = str_split($p1);
$TAmttmp = 0;
//echo "<br>sp11:".$spl1; // error convert array to string
$TAmttmp = $spl1;
echo "<br>TAmttmp: with useless cent".$TAmttmp;
if ($TAmttmp == 0.01) //so if there is 1 cent subtract the useless cent.
$TAmt = $TAmt - 0.01;
echo "<br>TAmt: with useless cent".$TAmt;
echo "<br>TAmt: without useless cent".$TAmt;
@Gumbo is right, we need to know the logic behind your conversions to provide a precise answer.
You could do an explode:
$var = explode('.',$_POST['val']); $digits = $var; // this will give you the digits after the decimal point
Now you can do what you need based on your logic.
You could also you use a
substr() where you find the decimal point (is it always three places from the right?) and then grab the substring.
Not sure which would be more efficient.