Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Working with currency

Author
Message
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 7th Jun 2018 03:54
I'm trying to work with currency and when i convert values to floats i get anomalies like -287.61 being converted to -287.609985
Is there anyway around this?
Does anyone have any ideas how i can get accurate values and work with them?
IronManhood
9
Years of Service
User Offline
Joined: 6th Feb 2015
Location: US
Posted: 7th Jun 2018 09:39
Tier 2 maybe..
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 7th Jun 2018 10:59
The answer is correct for a single-precision float
Tier 2 would be closer, but still not exactly -287.61. Neither will ever give you the exact value

There is enough accuracy in single-precision to round it to 2 decimal places and always get the correct answer.

You can perform any calculations by multiplying first by 100 and rounding - round(value# * 100)

You can display accurately using str(value#,2)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 7th Jun 2018 23:33
Thanks BatVink.
I have one other question;
I have a typed table containing various fields and i would like to sort it by any of the fields so i have a sort string as the first field of the type.
When i am sorting by a number i have to convert it to a string. How can i represent a number in a string so it will work when the number could be negative or positive. ie -1000 being less than -100
IronManhood
9
Years of Service
User Offline
Joined: 6th Feb 2015
Location: US
Posted: 8th Jun 2018 05:19
Well I would suggest writing a custom sorting function for each field so that you can get exactly what you want. The .sort() method is very basic.

Login to post a reply

Server time is: 2024-04-26 08:45:12
Your offset time is: 2024-04-26 08:45:12