Using a decimal variable to multiply

Hey there, I'm not much of a scripter or anything, just trying to get my event to work.


Basically, it's a common event that takes care of rewards my dungeons yield after triggering the "exit". A timer is running when entering the dungeon 


and is stored in a variable when triggering the dungeon exit. Timer value equals seconds left to 0. So, when I'm finishing a dungeon with 2min left, I have 120 stored in that variable.


My problem is I can't figure out how to use this variable to multiply the set rewards to multiply by variable / 100. I want the variable to be a multiplier, so 120 would be 1.2x the rewards.


I've been trying to get that to work for a few hours now :/


TL;DR: How can I bypass number rounding to use a variable as a small multiplier (e.g 2.5; 1.4; etc.). ( timer / 100 = multiplier)


I'm super tired, please forgive me poor wording/phrasing.. I hope I got my point across.


Thanks in advance.
 


--------------


Got it to work by reversing the order.


(Reward / 100) * timer


Uff..Math. Would be nice to know if there is a different way though.
I'm not terribly familiar with Javascript, but usually languages assume the return type should be that of the divisor, so make it a decimal as 100.0.
Javascript doesn't do any number rounding.


2 / 100 will give you 0.02.


0.02 * 1.5 will give you 0.03, as you would expect of floating point multiplication.


Your problem is the fact that you're storing it in a game variable before you perform the calculations.


Game variables rounds your numbers.
Thanks to both of you! @ZalerinianI've tried making it a decimal like that, didn't work 😛


@Tsukihime I'll try to make it work in a script call. Thanks for the info, I was kinda figuring out that game variables are doing some sort out auto rounding 😛 Could you give an example what I'd have to type? I'm really new-ish to JS. And couldn't find much information about that. Just so I know how to do it properly next time, would appreciate it! 


Again, thanks for your time.


______


Edit: 


I got it to work! There is probably a better way to do it tho.

var x = $gameVariables.value(81) / 100;


var exp = $gameVariables.value(82) * x;


var gold = $gameVariables.value(83) * x;


$gameVariables.setValue(82, exp);


$gameVariables.setValue(83, gold);
That's about the clearest way to do it: you have 3 variables, and you're updating 2 of them.

Original thread: https://forums.rpgmakerweb.com/threads/using-a-decimal-variable-to-multiply.61528/