A way to make a % vs whole number.

I'm making a banking system to where whenever the player has funds deposited in their bank, every 30 days there's an interest of 10% that calculates toward the saved balance and whatever is the total is added to the deposited amount.

Thing is, when I review the variable branch there isn't a way to make a decimal or % for the number. It's only constant. Is there a way around this?
Iam not sure if i fully understand but i assume you would have to use a second Variable for it,
which you can choose in the Conditional Branch.

Edit:
If you mean Control Variables Event Command, than you would have to do the Math manually.
i assume you would have to use a second Variable for it, which you can choose in the Conditional Branch.
That won't help - MZ's engine by default deals only in integers. So if you're using event commands for math and setting variables, that's all you'll ever get.

So instead of using Control Variables, use the Script event command and do the math there directly.

For example, if your bank account is variable 22 and you want to increase it by 10%, you'd do:
Code:
$gameVariables._data[22]*=1.1
So instead of using Control Variables, use the Script event command and do the math there directly.
No need, the Control Variables event command itself has a one-line scriptbox for this kind of thing. You can just use Control Variables, select Multiply and put 1.1 into the scriptbox.
That won't help - MZ's engine by default deals only in integers. So if you're using event commands for math and setting variables, that's all you'll ever get.

So instead of using Control Variables, use the Script event command and do the math there directly.

For example, if your bank account is variable 22 and you want to increase it by 10%, you'd do:
Code:
$gameVariables._data[22]*=1.1
Thanks a million for this. I figure it needed to be coded in. Just wasn't sure how to tackle it. 🙂
You can put 0.1 in the script section of a control variable command. If you want to raisr it is 10%, multinly the variable by 1.1 to get 110%.
No need, the Control Variables event command itself has a one-line scriptbox for this kind of thing. You can just use Control Variables, select Multiply and put 1.1 into the scriptbox.
That's not correct. Any use of the Control Variables event command uses the setValue() function and rounds the number.

Screenshot 2023-05-17 162309.png

This produces a value of 13.
Barebones Example about Percentage Calculated with Event Commands:

Var1 set to Game Data ; Gold
Var1*3 (Your Interest Rate 3%)
Var1/100
Event Command Change Gold Add Var1
@Bex That still won't produce decimal values, which is what the OP asked for.
That's not correct. Any use of the Control Variables event command uses the setValue() function and rounds the number.

View attachment 262127

This produces a value of 13.
Isnt that exactlybwhat they try to do? That is how I would do it. Never failed me so far.

You dont want to show the exact number, with all the decimals. The is quicly result in terrible long numbers.

Try 25 * 1.15 * 1.15 * 1.15 * 1.15 * 1.15 on a calculator and youll see what i mean.

If theyvwant to show like 2 decimals, there is a scriptcall for that, but I am on my phone. I'll need to open my project on my computer to see what it is. I know it was something simple.

Edit: This might help: https://www.w3schools.com/jsref/jsref_tofixed.asp
That is how I leanred it.
Ending results and I can confirm it works

1684357510187.png


I adjusted days to bank-days for its own variable, so that when the appropriate number has reached it can reset to 0 at the end.

Thanks for the help guys!
Spoiler: This was what I wrote before I saw the reply...
Code:
$gameVariables.setValue(1, ($gameVariables.value(2)*1.1).toFixed(2))

This script call should take the value of variable 2, raise it with 10%, and saves the outcome in variable 1.
The outcome in variable 1 will now be saved with only 2 decimals.

(Untested, but if my limited javascript knowledge is not failing me, then this is should do the trick.)

(EDIT: Sorry, I thought we were talking about MV... I don't even know if this is valid for MZ. The "toFixed" does add the decimals, though. Also in MZ. But seeing your last reply, I start doubting if that was even the question.)

Edit again:
Ending results and I can confirm it works

View attachment 262128

I adjusted days to bank-days for its own variable, so that when the appropriate number has reached it can reset to 0 at the end.

Thanks for the help guys!
Wait, what? This has the exact same outcome as using control variable to multiply the variable by 1.1. Then there is no need for a second variable either.

Edit one last time:
Forget all I said. I see the difference now. You want it to round up when at or over 0.5
I totally misunderstood the problem in the first place.
Spoiler: This was what I wrote before I saw the reply...
Code:
$gameVariables.setValue(1, ($gameVariables.value(2)*1.1).toFixed(2))

This script call should take the value of variable 2, raise it with 10%, and saves the outcome in variable 1.
The outcome in variable 1 will now be saved with only 2 decimals.

(Untested, but if my limited javascript knowledge is not failing me, then this is should do the trick.)

(EDIT: Sorry, I thought we were talking about MV... I don't even know if this is valid for MZ. The "toFixed" does add the decimals, though. Also in MZ. But seeing your last reply, I start doubting if that was even the question.)

Edit again:

Wait, what? This has the exact same outcome as using control variable to multiply the variable by 1.1. Then there is no need for a second variable either.

Edit one last time:
Forget all I said. I see the difference now. You want it to round up when at or over 0.5
I totally misunderstood the problem in the first place.
Yea, if you put 1.1 it isn't really 10%. Going to get a very big number 😅

Rounding up is needed to create a whole number of the amount the interest is. That way, it stays as a whole number.

Original thread: https://forums.rpgmakerweb.com/threads/a-way-to-make-a-vs-whole-number.157598/