spires Posted June 14, 2010 Share Posted June 14, 2010 Hi I have 3 strings. $discount2 = '12,000'; $discount3 = '1.00'; $discount4 = '10,000.01'; I need to add these together. $less234discount = $discount2 + $discount3 + $discount4; $less234discount = number_format($less234discount, 2); BUT, it will not calculate past the comma. It only sees: 12, 1, 10 NOT 12,000 1.00 10,000.01 How can I add these up correctly? Thanks for your help Link to comment https://forums.phpfreaks.com/topic/204751-calculation-help-needed/ Share on other sites More sharing options...
bugcoder Posted June 14, 2010 Share Posted June 14, 2010 try like this $discount2 = '12,000'; $discount3 = '1.00'; $discount4 = '10,000.01'; $result = str_replace(',','',$discount2)+str_replace(',','',$discount3)+str_replace(',','',$discount4); $result = number_format($result, 2); Link to comment https://forums.phpfreaks.com/topic/204751-calculation-help-needed/#findComment-1071957 Share on other sites More sharing options...
spires Posted June 14, 2010 Author Share Posted June 14, 2010 Works perfect thanks Link to comment https://forums.phpfreaks.com/topic/204751-calculation-help-needed/#findComment-1071964 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.