Skip to content

Commit bf12c96

Browse files
committed
Fix rounding error
1 parent df63bd9 commit bf12c96

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/store/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ export default createStore({
589589
); //get at least 1 rank XP when the task is completed
590590
task.rankXp += rankXpEarned; //increase rank XP based on task due date, task streak and task rank
591591
const rankLevel: number = Math.max(
592-
Math.floor(Math.pow(task.rankXp / 100, 1 / 4)),
592+
Math.floor(Math.pow((task.rankXp + 0.5) / 100, 1 / 4)),
593593
1,
594594
); //update rank level
595595
task.rank = rankLevel; //set task rank level
@@ -650,7 +650,10 @@ export default createStore({
650650
); //alert user to show how many XP they earned and points earned after completing the task
651651
//check if user has leveled up
652652
const userLevel: number = state.user.level; //set userLevel variable before calculating user level state
653-
state.user.level = Math.max(1, Math.floor(Math.cbrt(state.user.xp))); //calculate level based on how many XP and set level to 1 if total XP is 0
653+
state.user.level = Math.max(
654+
1,
655+
Math.floor(Math.cbrt(state.user.xp + 0.5)),
656+
); //calculate level based on how many XP and set level to 1 if total XP is 0
654657
if (state.user.level > userLevel) {
655658
alert(
656659
`Level Up!\nYou are now level ${state.user.level.toLocaleString("en-US")}!`,

0 commit comments

Comments
 (0)