PHPNewbie1234 Posted May 3, 2012 Share Posted May 3, 2012 $temp is currently 6. But the variable result can be changing every time to a different number so it is not a fixed value. Anyway, for this $temp * 1.1666666, the result will be 6.99999996. Since I used the floor function, it will be rounded down to 6. Is there any way when the value is more then>*.49999 it will stay at *.5 instead of *? Example: 6.51111111, 6.78948123, 6.9747124 Expected Output: 6.5 Example: 6.49999999, 6.12412431, 6.33452361 Expected Output: 6 Do note that, $temp value will be ever changing..thank you! Quote Link to comment https://forums.phpfreaks.com/topic/261988-simple-yet-complicated-mathematics/ Share on other sites More sharing options...
smerny Posted May 3, 2012 Share Posted May 3, 2012 floor(2 * $temp) / 2 example: 6.6 * 2 = 13.2 floor(13.2) = 13 13/2 = 6.5 6.4 * 2 = 12.8 floor(12.8 ) = 12 12/2 = 6 edited... Quote Link to comment https://forums.phpfreaks.com/topic/261988-simple-yet-complicated-mathematics/#findComment-1342516 Share on other sites More sharing options...
PHPNewbie1234 Posted May 3, 2012 Author Share Posted May 3, 2012 Doesnt work. What happens if the value is 6.87236235(random value) Expected Output: 6.5 6.87236235 * 2 = 13.7447247 13.7447247 + 0.5 = 14.2447247 floor(14.2447247) = 14 14/2 = 7. Not expected output. Quote Link to comment https://forums.phpfreaks.com/topic/261988-simple-yet-complicated-mathematics/#findComment-1342518 Share on other sites More sharing options...
smerny Posted May 3, 2012 Share Posted May 3, 2012 yea initially i was doing nearest half rather than floored half, edited post... fringe test: 6.9999999 * 2 = 13.999998 13.99998 floored = 13 13/2 = 6.5 6*2 = 12 12 floored = 12 12/2 = 6 6.4999 * 2 = 12.99998 floored = 12 12/2 = 6 6.5 * 2 = 13 floored = 13 13/2 = 6.5 Quote Link to comment https://forums.phpfreaks.com/topic/261988-simple-yet-complicated-mathematics/#findComment-1342519 Share on other sites More sharing options...
PHPNewbie1234 Posted May 3, 2012 Author Share Posted May 3, 2012 Thank you! That was indeed what i was looking for Quote Link to comment https://forums.phpfreaks.com/topic/261988-simple-yet-complicated-mathematics/#findComment-1342521 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.