The RPG Maker Resource Kit

RMRK RPG Maker Creation => Requests => Script Request => Topic started by: shintashi on June 07, 2010, 11:11:34 AM

Title: How to do Percents with decimals?
Post by: shintashi on June 07, 2010, 11:11:34 AM
How do I get something like this:

$game_variables[409] =
(($game_variables[408] * 11) /
$game_variables[410]) * 100


to work without the program totally screwing up the decimals?

for example, if var[408] is 10,

and var[410] is 120, I should get something that looks like 110/120 = 0.916...
that then gets converted into a percentage like 91.6%

obviously that's not what XP is doing, since it likes whole numbers.
Title: Re: How to do Percents with decimals?
Post by: modern algebra on June 07, 2010, 11:49:59 AM
Multiply it by 100 first then. You can also use floats.

$game_variables[408]*1100 / $game_variables[410]
Title: Re: How to do Percents with decimals?
Post by: shintashi on June 07, 2010, 03:38:37 PM
Quote from: modern algebra on June 07, 2010, 11:49:59 AM
Multiply it by 100 first then. You can also use floats.

$game_variables[408]*1100 / $game_variables[410]

I realized something like this about 5 am this morning but was too delirious to do anything about it (finals week). I was going to multiply everything by 10,000 first.

What's a floater?

I've heard of setting up variables A,B,C,D...for place holders.
Title: Re: How to do Percents with decimals?
Post by: cozziekuns on June 07, 2010, 03:41:28 PM
If you enter in:

$game_variables[xxxx] += 100, RPG Maker will automatically round to the nearest whole number. However, if you enter in $game_variables[xxxx] += 100.00, RPG Maker will automatically round to the nearest hundredth.

Basically, anything with a decimal point is a floating point number.
Title: Re: How to do Percents with decimals?
Post by: shintashi on June 15, 2010, 02:47:14 PM
Quote from: cozziekuns on June 07, 2010, 03:41:28 PM
If you enter in:

$game_variables[xxxx] += 100, RPG Maker will automatically round to the nearest whole number. However, if you enter in $game_variables[xxxx] += 100.00, RPG Maker will automatically round to the nearest hundredth.

Basically, anything with a decimal point is a floating point number.


do you think there's a way to set up Input number to have the option of decimals?
Title: Re: How to do Percents with decimals?
Post by: cozziekuns on June 15, 2010, 08:49:26 PM
Well, you could always just divide the variable by 100.00 (Zero's depend on how many places your willing to round of by) later.

Title: Re: How to do Percents with decimals?
Post by: tSwitch on June 15, 2010, 10:20:32 PM
what do you need exact decimals for, btw?