cwoodman Posted March 2, 2015 Share Posted March 2, 2015 This simple bit of code gives ridiculous answers... echo $Total;echo "<br>";echo $PrevTotal;echo "<br>";echo $Total-$PrevTotal; Example output: 3164,445312 or 1,395646-645 Any idea why? Link to comment https://forums.phpfreaks.com/topic/295025-subtraction-giving-wrong-answers/ Share on other sites More sharing options...
Barand Posted March 2, 2015 Share Posted March 2, 2015 Numeric variables should not contain formatting characters such as commas. Same goes for values held in a db table. 4,100 is treated as 4 (only numeric digits up to the first non-numeric digit) Format the numbers on output Link to comment https://forums.phpfreaks.com/topic/295025-subtraction-giving-wrong-answers/#findComment-1507281 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.