Depending if your number has a half like 1.5, 4.5 by checking if the last digit is a zero or not, then it will either show the full number with a decimal showing (1.5 and 4.5) or otherwise it will only show the first number, as it does not need an empty zero. It can show the integer number (1 or 4) instead of (1.0 and 4.0).
There are other ways of doing this, buts its also a good lesson in functions, and can see how it is returned to the function at the bottom.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<?php function amount($amount) { $original_amount = $amount; // copy original amount 1.5 $amount = substr($original_amount, 2); //takes of first 3 if ($amount=="0") { // if last = 0 then show only first number "1" return "<br>a".$amount = substr_replace($original_amount ,"",-2); } else { //show all of number as its 1.5 return "<br>b".$original_amount; } } // start $amount1 = "1.5"; $myamount = amount($amount1); echo $myamount."h"; ?> |