php - Odd casting behavior -


i have string "65.57". need int 6557

however...

(int) (((float) "65.57") * 100) === 6556

strangely, when broken up, works expected:

((float) "65.57") * 100) === 6557.0

and

(int) 6557.0 === 6557

but when inlined, i'm getting 6556.

don't mess floats, bring pain. :)

i'd strip out dot:

$s = '65.57'; $x = str_replace('.', '', $s); 

if need int, cast result:

$x = (int) str_replace('.', '', $s); 

Comments