phpretard Posted December 16, 2010 Share Posted December 16, 2010 Here is the number: $GrandTotal = "68.835"; $Deposit = round($GrandTotal , 2) * .5; echo $Deposit; I am looking for: 68.84 but the function doesn't seem to work right. Any help? Link to comment https://forums.phpfreaks.com/topic/221865-problem-rounding-decimals/ Share on other sites More sharing options...
johnny86 Posted December 16, 2010 Share Posted December 16, 2010 You are multiplying your result with 0.5 at the end. with $Deposit = round($GrandTotal , 2); it should work right. Link to comment https://forums.phpfreaks.com/topic/221865-problem-rounding-decimals/#findComment-1148100 Share on other sites More sharing options...
phpretard Posted December 16, 2010 Author Share Posted December 16, 2010 try it ... it isn't working right Link to comment https://forums.phpfreaks.com/topic/221865-problem-rounding-decimals/#findComment-1148102 Share on other sites More sharing options...
johnny86 Posted December 16, 2010 Share Posted December 16, 2010 <?php $GrandTotal = "68.835"; $Deposit = round($GrandTotal , 2); echo $Deposit; // Result: 68.84 ?> Link to comment https://forums.phpfreaks.com/topic/221865-problem-rounding-decimals/#findComment-1148106 Share on other sites More sharing options...
phpretard Posted December 16, 2010 Author Share Posted December 16, 2010 What could I be doing wrong then? // do some math $PZTotal = "17.97"; $FCTotal = "56.97"; $CHTotal = "65.7"; $GrandTotal = $PZTotal + $FCTotal + $CHTotal; $Deposit = round($GrandTotal , 2) * .5; [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/221865-problem-rounding-decimals/#findComment-1148113 Share on other sites More sharing options...
johnny86 Posted December 16, 2010 Share Posted December 16, 2010 // do some math $PZTotal = "17.97"; $FCTotal = "56.97"; $CHTotal = "65.7"; $GrandTotal = $PZTotal + $FCTotal + $CHTotal; $Deposit = round($GrandTotal , 2) * .5; // This is wrong remove * .5 <-- that multiplys the result with 0.5 // which meand that it is divided by 2.... //SO Correct: $Deposit = round($GrandTotal , 2); Link to comment https://forums.phpfreaks.com/topic/221865-problem-rounding-decimals/#findComment-1148114 Share on other sites More sharing options...
phpretard Posted December 16, 2010 Author Share Posted December 16, 2010 // do some math $PZTotal = "17.97"; $FCTotal = "56.97"; $CHTotal = "65.7"; $GrandTotal = $PZTotal + $FCTotal + $CHTotal; $Deposit = round($GrandTotal , 2) * .5; // This is wrong remove * .5 <-- that multiplys the result with 0.5 // which meand that it is divided by 2.... //SO Correct: $Deposit = round($GrandTotal , 2); The deposit is half of the $GrandTotal. Where should I do that math? Link to comment https://forums.phpfreaks.com/topic/221865-problem-rounding-decimals/#findComment-1148116 Share on other sites More sharing options...
phpretard Posted December 16, 2010 Author Share Posted December 16, 2010 $Half = $GrandTotal * .5; $Deposit = round($Half, 2); This works. Thank you all! Link to comment https://forums.phpfreaks.com/topic/221865-problem-rounding-decimals/#findComment-1148117 Share on other sites More sharing options...
idiotstrike Posted December 16, 2010 Share Posted December 16, 2010 You need to divide it first and then round it. $Deposit = $GrandTotal * 0.5; $Deposit = round($Deposit, 2); Link to comment https://forums.phpfreaks.com/topic/221865-problem-rounding-decimals/#findComment-1148120 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.