Skip to content

Commit

Permalink
fix: rounding errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Coffeelot committed Dec 21, 2024
1 parent d6cd8e6 commit be6ea01
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1624,7 +1624,7 @@ end)

RegisterServerCallback('cw-racingapp:server:purchaseCrypto', function(source, racerName, cryptoAmount)
local src = source
local moneyToPay = math.floor(cryptoAmount/Config.Options.conversionRate)
local moneyToPay = math.floor((1.0*cryptoAmount)/Config.Options.conversionRate)
if UseDebug then
print('Buying Crypto')
print('Crypto Amount:', cryptoAmount)
Expand All @@ -1639,12 +1639,12 @@ end)

RegisterServerCallback('cw-racingapp:server:sellCrypto', function(source, racerName, cryptoAmount)
local src = source
local rounded = cryptoAmount/Config.Options.conversionRate
local afterFee = math.floor(rounded - rounded*Config.Options.sellCharge)
local money = (1.0*cryptoAmount)/Config.Options.conversionRate
local afterFee = math.floor(money - money*Config.Options.sellCharge)
if UseDebug then
print('Selling Crypto')
print('Crypto Amount:', cryptoAmount)
print('In money:',rounded)
print('In money:',money)
print('After fee:',afterFee)
end
if handleRemoveMoney(src, 'racingcrypto', cryptoAmount, racerName) then
Expand Down

0 comments on commit be6ea01

Please sign in to comment.