|
mandy Novice
Joined: 10 Jul 2007 Posts: 47
|
Posted: Tue Jul 10, 2007 1:43 pm
Variables, Decimals and simple #MATH |
I saw that there is some sort of %float thing to make sure a variable is a decimal, but I couldn't make sense of it, and with the nice warning that was included - I'm not sure it will work any how.
Essentially, I want to take 2 variables, each having 2 to 4 decimal places, using simple math to create a third variable.
IE: #math @CC (@BB-@AA)
The values of @AA, @BB will be carried out to 2 to 4 decimal places and @CC will need to reflect the same amount of decimal places as reflected in @AA, @BB. |
|
|
|
mandy Novice
Joined: 10 Jul 2007 Posts: 47
|
Posted: Tue Jul 10, 2007 2:51 pm |
I just tried to be real dumb to see if it would work - but maybe this might make this a little clearer to those who might be willing to help.
#if (@gxpdig<10) {#variable GXPF (@gxpdig@gxpdex1@gxpdec2@gxpdec3@gxpdec4)}{#if (@gxpdig>=10 AND @gxpdig<100) {#variable GXPF (@gxpdig@gxpdex1@gxpdec2@gxpdec3)}{#if (@gxpdig>100) {#variable GXPF (@gxpdig@gxpdex1@gxpdec2)}{}
#math gxpgain (@oldgxp-@gxpf)
#show GXP Gain: @gxpgain
Basically, if total GXP (Represented by smashing all these variables together throwing a decimal point after gxpdig (@gxpdig.@gxpdex1@gxpdec2@gxpdec3@gxpdec4)
If my experience is less than 10%, it is displayed out to 4 decimal places, if it its > than 10 but less than 100 then it is displayed out to three spaces, and finally if it is 100% it is displayed in 2 decimal places.
I've been working on this for quite a few hours now, so I'm sure I'm barking up the wrong tree but my sense of logic is not getting me anywhere. |
|
|
|
Tech GURU
Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: Tue Jul 10, 2007 4:02 pm |
It sounds like you want to use %format so something like this should do what you want.
#var CC %format(4,%eval(@BB-@AA)); #show @CC |
|
_________________ Asati di tempari! |
|
|
|
mandy Novice
Joined: 10 Jul 2007 Posts: 47
|
Posted: Tue Jul 10, 2007 4:31 pm |
Well, that got me an answer other than 0 :) But, it's not doing the math correctly. in fact its giving me the same response of -70.6000. BUT I think that is a huge improvement from steady 0's, right?
|
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Tue Jul 10, 2007 4:36 pm |
I tried this earlier using the %eval function:
#var a 4
#var b 2.34
#say %eval(@a-@b)
which gave quite a strange result - it was VERY NEARLY right, but had some kind of rounding error. Pretty weird for such simple maths. Perhaps it's fixable by %fomat-ing the result, though. |
|
|
|
Arminas Wizard
Joined: 11 Jul 2002 Posts: 1265 Location: USA
|
Posted: Tue Jul 10, 2007 4:42 pm |
Is this what you want to do?
#show %format(4,%eval(%float(5.25)-3.241))
Gives.
2.0090 |
|
_________________ Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Tue Jul 10, 2007 4:44 pm |
As does "#show %format(4,%eval(5.25-3.241))", which possibly explains the earlier confusion about %float. But that's exactly what I meant.
|
|
|
|
mandy Novice
Joined: 10 Jul 2007 Posts: 47
|
Posted: Tue Jul 10, 2007 7:41 pm |
I'm trying everything - I still can't get it to work! I've worked more on this 'function' that most people do in a week at a job they get paid to do - heh
|
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Tue Jul 10, 2007 7:45 pm |
What about them isn't working? It could be a result of that crazy rounding error I was getting before. Just FYI, I can't reproduce the error in CMUD.
|
|
|
|
Tech GURU
Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: Tue Jul 10, 2007 7:57 pm |
Why don't you post your entire script. I think there may be a bug somewhere else.
Also post the values of your variables. |
|
_________________ Asati di tempari! |
|
|
|
|
|