pdo - MySQL Float(7,2) to PHP Float -
i fetching (with php pdo) mysql value (stored in signed float(7,2) format).
result ===================== database = 8.9 //correct value php = 8.8999996185303 //fetch php pdo sample code:
$qry = 'select hours sample filter=?;'; $stmt = $db->prepare($qry); $stmt->execute(array($filter)); while($row = $stmt->fetch(pdo::fetch_assoc)) { echo $row['hours']; } what best possible way fetch data db? ive read floating point approximalization issue in php. thinking perhaps change sql like:
select (hours * 100) butsoexpensiveondatabase etc... or using round or number_format in php. guys suggest , why?
changing table structure not option!
(reason: old legacy code need support + no time + no budget)
you can this
"select round(hours, 2) sample filter=?;"
Comments
Post a Comment