ahmedm177 Posted January 9, 2008 Share Posted January 9, 2008 i have an array value as following $result['val1'] when i do echo for it i have number like that 4,100,000 after that if i multiplied it by 2 ( as example ) the result will be 8 although the result must be 8,200,000 so what should i do ? Link to comment https://forums.phpfreaks.com/topic/85195-solved-problem-in-numer-format/ Share on other sites More sharing options...
revraz Posted January 9, 2008 Share Posted January 9, 2008 Post the relevant code. so what should i do ? Link to comment https://forums.phpfreaks.com/topic/85195-solved-problem-in-numer-format/#findComment-434627 Share on other sites More sharing options...
The Little Guy Posted January 9, 2008 Share Posted January 9, 2008 It is most likely because of the commas. so... <?php $number = 4,100,000 $num = str_replace(",",$number); echo number_format($num * 2); ?> Link to comment https://forums.phpfreaks.com/topic/85195-solved-problem-in-numer-format/#findComment-434633 Share on other sites More sharing options...
redarrow Posted January 9, 2008 Share Posted January 9, 2008 you sure you can use the * in number format looks strange sorry? Link to comment https://forums.phpfreaks.com/topic/85195-solved-problem-in-numer-format/#findComment-434648 Share on other sites More sharing options...
The Little Guy Posted January 9, 2008 Share Posted January 9, 2008 yes, because it will multiply it, then it will be a number which the function will use, it won't use $num * 2 but it will use the product of $num * 2 Link to comment https://forums.phpfreaks.com/topic/85195-solved-problem-in-numer-format/#findComment-434657 Share on other sites More sharing options...
ahmedm177 Posted January 9, 2008 Author Share Posted January 9, 2008 It is most likely because of the commas. so... <?php $number = 4,100,000 $num = str_replace(",",$number); echo number_format($num * 2); ?> Thank you little guy your code solve my problem, but there is a small addition <?php $number = 4,100,000 $num = str_replace(",","",$number); echo number_format($num * 2); ?> Link to comment https://forums.phpfreaks.com/topic/85195-solved-problem-in-numer-format/#findComment-434819 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.