in my application i do some math and the result can be float or int
I want to show the final result with two digits after the decimal point max ... if the result is a floating point number
There are two options:
number_format($final ,2);
and
sprintf ("%.2f", $final );
but the problem is ... if my end result is int, like 25 I end up with
25.00
or if the end result is something like 12.3 , it gives me
12.30
and i don't want
Is there a way to format a number to show 2 digits after a floating point ONLY IF this is a floating point number with more than two digits after a decimal point? or should I do some checking before formatting my number?
source share