[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Jscript
. . -> [Subject]  Subtracting decimals

Subtracting decimals

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Sirius096   (12 posts)  [Biography] 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
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] 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
[Go to top] top

Posted by Sirius096   (12 posts)  [Biography] bio
Date Reply #2 on Wed 08 Feb 2006 04:43 AM (UTC)
Message
Woot!
parseFloat worked a charm!
Thanks alot. :)
[Go to top] 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.


10,501 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]