moiisam10 Posted August 17, 2015 Share Posted August 17, 2015 Hello guys... Am here again maybe with a noob question.. but well am just triying to learn all possible. I got a variable... $lal = 4820.492 and i need to divie all in 2... like $lal2 = 2410.246 I triyied with $lal2 = $lal/2; echo $lal2; But i just get the first character. so its "2" , i triyed with explode but dont work or dont know, with number_format and i dont know how to make it work.. Thanks in advanced to all. Link to comment https://forums.phpfreaks.com/topic/297836-divide/ Share on other sites More sharing options...
Ch0cu3r Posted August 17, 2015 Share Posted August 17, 2015 I get your expected result 2410.246 $lal = 4820.492; $lal2 = $lal/2; echo $lal2; // output 2410.246 Are your sure $lal is what you expect it is? What does var_dump($lal); return? Link to comment https://forums.phpfreaks.com/topic/297836-divide/#findComment-1519111 Share on other sites More sharing options...
moiisam10 Posted August 17, 2015 Author Share Posted August 17, 2015 I get your expected result 2410.246 $lal = 4820.492; $lal2 = $lal/2; echo $lal2; // output 2410.246 Are your sure $lal is what you expect it is? What does var_dump($lal); return? Well... Really i get the $lal with this. $lal = $row[0]->nodeValue; from curl. Link to comment https://forums.phpfreaks.com/topic/297836-divide/#findComment-1519112 Share on other sites More sharing options...
Ch0cu3r Posted August 17, 2015 Share Posted August 17, 2015 Oh. This is from yesterday? You cannot do math operations with numbers which are formatted. You need to remove the number formatting so its whole number // remove number formatting $lal = str_replace(',', '', $row[0]->nodeValue); // now divide by 2 $lal2 = floatval($lal) / 2; echo $lal2; If you dont remove the formatting PHP will truncate the value before the comma, so only 4 will be divided by 2 this why the result is 2 Link to comment https://forums.phpfreaks.com/topic/297836-divide/#findComment-1519114 Share on other sites More sharing options...
moiisam10 Posted August 17, 2015 Author Share Posted August 17, 2015 Oh. This is from yesterday? You cannot do math operations with numbers which are formatted. You need to remove the number formatting so its whole number // remove number formatting $lal = str_replace(',', '', $row[0]->nodeValue); // now divide by 2 $lal2 = floatval($lal) / 2; echo $lal2; If you dont remove the formatting PHP will truncate the value before the comma, so only 4 will be divided by 2 this why the result is 2 Thanks again bro , i look like a real noob.. Link to comment https://forums.phpfreaks.com/topic/297836-divide/#findComment-1519115 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.