godsent Posted January 2, 2009 Share Posted January 2, 2009 Im trying rebuild formula from java to php, and im not going very well. I don't know what im doing wrong. My PHP verssion: function getLevelForXP($exp) { $points = 0; $output = 0; for ($lvl = 1; $lvl < 100; ++$lvl) { $points += floor( $lvl + 300.0 * pow(2.0, $lvl / 7.0)); $output = floor($points / 4); if (($output - 1) >= $exp) { return $lvl; } } } Real java verssion: public static int getLevelForXP(int exp) { int points = 0; int output = 0; for (int lvl = 1; lvl < 100; lvl++) { points += Math.floor((double) lvl + 300.0 * Math.pow(2.0, (double) lvl / 7.0)); output = (int) Math.floor(points / 4); if ((output - 1) >= exp) { return lvl; } } return 99; } If you know please help me out Link to comment https://forums.phpfreaks.com/topic/139257-solved-help-with-formula-math-calc/ Share on other sites More sharing options...
ratcateme Posted January 2, 2009 Share Posted January 2, 2009 function getLevelForXP($exp) { $points = 0; $output = 0; for ($lvl = 1; $lvl < 100; $lvl++) { $points += floor( $lvl + 300.0 * pow(2.0, $lvl / 7.0)); $output = floor($points / 4); if (($output - 1) >= $exp) { return $lvl; } } return 99; } looks good i only added the return and move the ++ in the for loop Scott. Link to comment https://forums.phpfreaks.com/topic/139257-solved-help-with-formula-math-calc/#findComment-728428 Share on other sites More sharing options...
godsent Posted January 2, 2009 Author Share Posted January 2, 2009 it works, thanks! Link to comment https://forums.phpfreaks.com/topic/139257-solved-help-with-formula-math-calc/#findComment-728437 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.