Hello all,
I am working on something in Tier 1 for a client that involves the user to click a bunch of VirtualButtons to create a string of numbers (imagine a calculator). The numbers can be any number from 0 to 9999.99. I achieve this by appending the clicked number to a string.
Example:
Click 1 -> current_number$ = current_number$ + "1"
Click 2 -> current_number$ = current_number$ + "2"
Click decimal, then click 3 -> current_number$ = current_number$ + "." + "3"
...and so on.
This works and displays rather beautifully, until I need to store the number as a float for later processing.
I have checks in place to determine whether the input exceeded two decimal places (and limiting the number of times the decimal button can be pressed) to prevent conversion errors.
I first tried the Val() function, and got an integer output. After double checking the documentation, I found
ValFloat(). This seemed simple and straightforward enough. I compiled, ran, input my test data, and everything seemed to be correct up until I went into the triple digits.
Input 1.50 outputs 1.500000
Input 6.66 outputs 6.660000
Input 666.66 outputs 666.659973
I thought maybe there was an error in my code, so I put a few Message() statements in to try to trap it. Completely bypassing input, I tried:
current_number$ = "666.66"
Message(current_number$)
and got the output, 666.66
cur_number# = 0.0
Message(str(cur_number#))
and got the output, 0.000000
cur_number# = ValFloat(current_number$)
Message(str(cur_number#))
and got the output, 666.659973
current_number$ = "666.66"
Message(str(ValFloat(current_number$)))
and got the same output as above.
I did a bit of searching on these forums, and found a few string to float conversion functions that worked for others prior to the ValFloat() function being officially in AGK. As a shot in the dark, I tried those, and get the same botched number output, so I am wondering if this is a floating point computation error on AGK's part, at the core level. I am pretty sure it is not a floating point issue at the processor level on my end, as it is an Intel i3. It is an older processor (a few years old), but it is modern enough that there shouldn't be any floating point precision errors like Intel and AMD had in the early days (if anyone remembers those...)
This has me absolutely stumped. I am currently running AppGameKit 108 Beta 11 on Windows 7 Home Premium x64. Or at least I think I am running 108. I downloaded 108 the installer from my products page, but the about box still says Build 107. I uninstalled 107 completely prior to installing 108. My only other testing machine cannot run AppGameKit (older netbook, WinXP).
Any ideas on as to why this is happening, or a way I can achieve the same function without concatenating a string then type converting to a float, would be much appreciated.
Thanks for taking the time to read this post. If I have missed anything, please feel free to ask.