Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Jscript
➜ Subtracting decimals
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Sirius096
(12 posts) Bio
|
Date
| Wed 08 Feb 2006 01:03 AM (UTC) |
Message
| Hi there.
I wrote a function to take a certain number away from 100 and then divide by another number, eg:
(100-4.598)/.0125
Now my problem is, MC (or jscript?) can't seem to handle taking a decimal off 100, it just rounds the decimal up and produces a whole number. I have the value I'm taking off 100 stored as a variable and my function is written as such;
function GXPCounter(g2n)
{
var g2n = world.GetVariable("g2n");
world.SetVariable("g2n2", parseInt(100-(world.GetVariable("g2n"))));
world.Note("Rounds for FM: " + parseInt((world.GetVariable("g2n2"))/.0125));
}
Can someone tell me what I'm doing wrong?
Cheers
-Siri | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #1 on Wed 08 Feb 2006 03:30 AM (UTC) |
Message
| parseInt is probably your problem. Integers don't have decimal points. Try parseDouble or parseFloat -- but I'm not sure what the exact function is. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Sirius096
(12 posts) Bio
|
Date
| Reply #2 on Wed 08 Feb 2006 04:43 AM (UTC) |
Message
| Woot!
parseFloat worked a charm!
Thanks alot. :) | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
11,714 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top