Home   Help Search Login Register  

Author Topic: Simple Maths question  (Read 429 times)

0 Members and 1 Guest are viewing this topic.

Unnamed

  • Guest
Simple Maths question
« on: 25 Apr 2004, 00:11:57 »
Hi,

I want to get all the numbers following a decimal point. Trouble is I have to do some subtraction first, which is where I come unstuck:

In an ideal world:

Quote
500.4 - 500=0.4

But in OFP it goes more like:

Quote
500.4 - 500=0.399994

and...

500.7 - 500=0.700012

500.8 - 500=0.799988

Any ideas how to get sensible results back from these subtractions?

Cheers

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re:Simple Maths question
« Reply #1 on: 25 Apr 2004, 00:55:36 »
lo unnamed,

You're right - 500.4 - 500 = 0.3994996 (or so  :D )

But:

Code: [Select]
hint format ["%1",(((500.4 * 10) - (500 *10)) / 10)]
gave me a result of: 0.4

P.S: not sure wether multiplicating a number by a factor of 10
is enough in case of bigger numbers (or higher values behind the comma), but i'm pretty sure that the higher the factor gets,
the higher the accuracy of the result will be.

~S~ CD
« Last Edit: 25 Apr 2004, 00:56:20 by Chris Death »
Dont argue with idiots....they will bring you down to their level and beat you there with experience.

How to use Waypoint type Scripted

Unnamed

  • Guest
Re:Simple Maths question
« Reply #2 on: 25 Apr 2004, 02:55:21 »
Quote
not sure wether multiplicating a number by a factor of 10
is enough in case of bigger numbers (or higher values behind the comma), but i'm pretty sure that the higher the factor gets,
the higher the accuracy of the result will be.

Yeah just move everything to the left of the decimal, so you avoid the problem. I can get everything to the left Ok.

The range of numbers will be no higher than .999 , I can do some If statements to check if I need to multiply & divide by 10, 100 or 1000.

Thanks Chris  :)