Non-threaded

Forums » Advanced Editor Forum » Read Thread

Get help from the experts on variables, scripts, items, and other scary things.

[Answered] Handling decimals

17 years ago

Hey guys, ive been trying to work with percentages in scripting and it is not working for me.

Sample Code:

IF %FACTOR = 1 THEN
%HEALTH := %HEALTH - (%HEALTH*.5)

The above will not work. I want it that if a factor turns up "1" then half of your life is lost. In the debugger, it says that it cannot define the '.' the dot, or the decimal in this case.

i have tried:

IF %FACTOR = 1 THEN
%HEALTH := %HEALTH - (%HEALTH * (50/100))

but this does not work either. HAve you guys run into this problem, and do you know a fix?

[Answered] Handling decimals

17 years ago
Maybe health divided by two?

IF %FACTOR = 1 THEN
%HEALTH := %HEALTH - (%HEALTH / 5)

[Answered] Handling decimals

17 years ago
yes, well that works for the 50% but that is only a snippet of the code, i have more percentages that range from 3% to 95%

[Answered] Handling decimals

17 years ago

alex is a genius, here is what we can do to substitue for decimals:

%HEALTH := %HEALTH * 50 (percentage)
%HEALTH := %HEALTH / 100

[Answered] Handling decimals

17 years ago
Yeah, you can do it with numbers that aren't out of 100 as well. That's what you do in tests when the teacher is too lazy to give you a percentage mark. They give you a mark out of whatever, let's say 34 out of 39 for an example, and then you divide 34 (the numerator) by 39 (the denominator) and multiply it by a hundred and you have a percentage out of a hundred.

34/39 = 87.17%

[Answered] Handling decimals

17 years ago

variables are integers tho, so im unsure if you did:

9/10 * 100

although the end result is an integer, it begins as a decimal...

[Answered] Handling decimals

17 years ago

Hmm...that's a good idea but- oh, hell, i'll quit pretending that I know what you're talking about. You lost me at scripting. lol. (as you can see I still doin't have a clue about scripting)

riley

[Answered] Handling decimals

17 years ago
Oh.. I thought it would automatically round it off or something like that. Silly me.

[Answered] Handling decimals

17 years ago
lol no worries, even i didnt remember that variables were integers only, alex told me they were, so we switched to something that did not deal with decimal numbers.

[Answered] Handling decimals

17 years ago

I would like to add for the record that when some operation done by scripting results in a decimal number, the system rounds DOWN. yes,  i said down, not up.

((50 * 95) / 100) is basically getting 95% from 50, which really is 47.5 but the cys scripting engine returns the value as 47.