Page 1 of 1

Why this function return -2.8421709430404E-14 ?

Posted: Mon Apr 18, 2011 3:20 am
by gayanp

Code: Select all

<?Php

function getDiscount() {
$discount = 100;
return (245/100) * $discount;
}

echo 245-getDiscount();

?>

Re: Why this function return -2.8421709430404E-14 ?

Posted: Mon Apr 18, 2011 4:59 am
by Weirdan
Because it operates on float numbers (you've got float when you divided integer by integer).

Re: Why this function return -2.8421709430404E-14 ?

Posted: Mon Apr 18, 2011 6:01 pm
by McInfo
Try BCMath.