Able to stop calculation returning 'e-002' at end?

For questions about using Classic.

Post » Tue Apr 17, 2012 6:38 am

It's extremely frustrating having my values randomly returning these
because it makes trying to balance the values and growth really hard
when it will be something like 0.16 and then 2.68e-002...
I have no idea what the actual values it is ranging from are and I
can't try and workout how to calculate that every single time it
changes, as it does so continuously.

I'd extremely appreciate if anyone knows how to stop this happening,
it's an absolute nightmare and I've lost far too much time over this.
B
3
G
2
Posts: 58
Reputation: 1,166

Post » Tue Apr 17, 2012 7:09 am

Also, sometimes I have a value and I add 0.1 every tick. If I print this value after 10 ticks, it will return 10.0000000000010 or something like that

Here's a capx
After more or less 5 seconds, it displays many zeroes

Also, notice that I used "every 1 second" but the timer seems a bit random, why is that?7Soul2012-04-17 07:18:07
B
83
S
21
G
15
Posts: 1,039
Reputation: 15,134

Post » Tue Apr 17, 2012 7:50 am

Use the "FormatDecimal()" system expression, it's output won't become 2.68e-002.
ex.
FormatDecimal(0.0268, 4) -> "0.0268"

@7Soul
That has to do with floating point precision.
Short Answer:
0.1 can't be exactly represented in binary, so a close approximation is used. When adding the number multiple times the inaccuracy grows. It is an issue with all computers. The number will not always be exact but it will be accurate to a certain number of digits, so the error is usually insignificant.

Long Answer:
http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.htmlR0J0hound2012-04-17 07:50:56
B
79
S
24
G
53
Posts: 4,728
Reputation: 40,219

Post » Tue Apr 17, 2012 5:54 pm

@R0J0hound
There's no FormatDecimal on C2 :/
And thx for the explanation
B
83
S
21
G
15
Posts: 1,039
Reputation: 15,134

Post » Wed Apr 18, 2012 3:20 am

Thank you very much :)

It seems to work, however.....What on earth is this message about
'Cannot add with integer and string. Operator had no effect' error
that is caused when using FormatDecimal?
As well as 'Cannot add with float and string. Operator had no effect'

Now it won't let me add that variable in other calculations??sparkfeather2012-04-18 03:26:43
B
3
G
2
Posts: 58
Reputation: 1,166

Post » Wed Apr 18, 2012 6:02 am

FormatDecimal, as ROJO showed in his example and can be seen in the wizard, outputs a string, not a number. There's no need to convert a number using FormatDecimal into a string and then keep on calculating with it. Just calculate with the number itself, not its human readable text form.

btw, it isn't that hard to read. 2.68e-002 just means: shift the number 2.68 two decimal places to the right (2.68->0.268->0.0268)
It's the same with everything else. 2.68e-003 = shift 3 decimal places to the right = 0.00268, etc.
There's also the other way round. 1.5e+003 would mean, shift the number three decimal places to the left = 1500
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Wed Apr 18, 2012 10:04 am

Ahhh thank you, I hadn't realized that was meant to indicate it was being
turned into a string, just thought that was to highlight what the end result was.


Doing that would work if the number wasn't changing so radically as I mentioned,
which makes that more misleading/distracting than anything.
But I did get around it by as you said using the number itself in its
continued calculation, and I instead made another variable for it to
send the FormatDecimal result so I can keep an eye on it there :).

Thank you both very much for your help again, I can finally continue
moving forward with the project.
B
3
G
2
Posts: 58
Reputation: 1,166

Post » Wed Apr 18, 2012 5:42 pm

[QUOTE=7Soul] @R0J0hound
There's no FormatDecimal on C2 :/
And thx for the explanation[/QUOTE]

I have tried using FormatDecimal to format text into currency, and always get an error for unknown expression.


Original format:

"$" &(Balance/100) &"." &right("00" &Balance%100,2)

has issues with displaying cents properly.

Looking for a better solution, or advice on what may be causing the error.
B
9
S
1
G
1
Posts: 3
Reputation: 536

Post » Wed Apr 18, 2012 7:42 pm

@seridras
try this:
"$" &int(Balance) &"." &right("00" &(Balance*100)%100,2)
B
79
S
24
G
53
Posts: 4,728
Reputation: 40,219

Post » Wed Apr 18, 2012 10:26 pm

Adding int() did the trick.

I left off the (Balance*100)%100 since Balance was already storing cents in integer form (holdover from previous reference materials).

Thanks!
B
9
S
1
G
1
Posts: 3
Reputation: 536

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 9 guests