php - why (int) ( 307.03 * 100) = 30702 -
this question has answer here:
- is floating point math broken? 20 answers
today coworker stumbled on this:
$s = floatval("307.03"); $s = $s * 100; echo intval($s); //30702
float value or round($s) return 30703 expected.
i guess it's problem connected float int approximation why happen ?
the float val stored 307.02999 or intval truncate number, no rounding, hence 30702.
Comments
Post a Comment