Skip to content

Commit ee9717d

Browse files
committed
fix: decimal fixes on knowledge kingdom
1 parent ceac3e7 commit ee9717d

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

store/tycoon/knowledge-kingdom/actions.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ export default {
4141
const dynamicCost = base * Math.pow(1.15, ownedCount)
4242
const finalCost = dynamicCost < 100 ? Math.round(dynamicCost * 10) / 10 : Math.floor(dynamicCost)
4343

44-
if (state.gold < finalCost) return false
44+
// Epsilon for floating point: 0.1*10 can be 0.9999999999999999
45+
const goldRounded = Math.round(state.gold * 100) / 100
46+
const costRounded = Math.round(finalCost * 100) / 100
47+
48+
if (goldRounded < costRounded) return false
4549

4650
commit('SUBTRACT_GOLD', finalCost)
4751
commit('BUY_ITEM', itemId)

store/tycoon/knowledge-kingdom/mutations.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ export default {
1919
},
2020

2121
ADD_GOLD(state, amount) {
22-
state.gold += amount
22+
state.gold = Math.round((state.gold + amount) * 100) / 100
2323
},
2424

2525
SUBTRACT_GOLD(state, amount) {
26-
state.gold -= amount
26+
state.gold = Math.round((state.gold - amount) * 100) / 100
2727
},
2828

2929
SET_ITEMS(state, items) {

0 commit comments

Comments
 (0)