Used to not really know how to calculate interest and then apply it to a number value which I know many people still don’t.
Just a quick tutorial I thought I would share as I used to never find really any good help/sources.
I am aware you could do BankCash / 100
for the interest but that didn’t exactly work out well for my application. I wanted to put this here as I know someone will mention it.
Code
-- change this to whatever you're using for your game.
local BankCash = 20,000,000 -- remove commas. Theyre there to help assist with understanding
local function Calc_Interest(): number -- little bit of oop
return math.floor(BankCash / (BankCash / 1) * 1) -- 20m = 200k = 1%
end
local function ApplyInterest()
local Interest = Calc_Interest() -- returns a number
BankCash += math.round( (BankCash / (Interest * 100 ) * Interest ) )
end
print(BankCash) -- old cash
ApplyInterest()
print(BankCash) -- new cash
This also should work with any number like 10, 100, 1000, etc.
Hopefully this helps whom ever it may concern. Wrote this at 3:36 am so please do excuse me if it looks over complicated and what not. If I remember I will probably simplify it.