# 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 Chat / Working with currency

Message
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?
Posted: 7th Jun 2018 09:39
Tier 2 maybe..
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
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
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.