|
horks Apprentice
Joined: 20 Jul 2001 Posts: 127 Location: USA
|
Posted: Fri May 10, 2002 6:03 pm
Math with Floating Points |
Is the floating point value going to get any more accurate than it currently is in beta 6.26a?
Currently, it is not going to do me any good because it is just too inaccurate. Here's an example:
#show %eval(2.0+2.1)
results in 4.09999990463257
I don't need a number with so many decimal points. I'm really glad this support has been added, but it needs to be accurate before I can use it in my scripts.
Is there a work around? I don't need so many decimal points. At most, I'll need 3.
What I've been doing, is this:
#var a %replace(2.0,".")
#var b %replace(2.1,".")
#var c %eval(@a+@b)
#var c %concat(%leftback(@c,1),".",%rightback(@c,1))
#show @c
However, this solution only works if I know how many decimal points there are going to be... |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Fri May 10, 2002 7:30 pm |
This belongs in the beta forum.
LightBulb
Vague questions get vague answers |
|
|
|
Sildaren Wanderer
Joined: 19 Jul 2001 Posts: 59 Location: Germany
|
Posted: Sat May 11, 2002 11:51 am |
#show %format("&10.2f",%eval(2.0+2.1))
displays
4.10
The only other way I can think of right now, is if you need, say, 2 decimals, to multiply all values with 100, and use intergers instead.
Maybe with a user defined function to display them:
#FUNC form {%concat(%if(%1<99,0,%eval(%1/100)),".",%rightback(%eval(%1+100),2))}
Now
#show @form(%eval(200+210))
displays
4.10
and
#show @form(%eval(1+3))
displays
0.04
The integer workaround works in the public version as well. |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Sat May 11, 2002 4:25 pm |
Oh yeah, this isn't accurate enough? It's accurate to 7 decimal places, how much accuracy do you think you need?
LightBulb
Vague questions get vague answers |
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|