File tree Expand file tree Collapse file tree 2 files changed +7
-3
lines changed
store/tycoon/knowledge-kingdom Expand file tree Collapse file tree 2 files changed +7
-3
lines changed Original file line number Diff line number Diff 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 )
Original file line number Diff line number Diff 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 ) {
You can’t perform that action at this time.
0 commit comments