Thread: DOE: Locations Extension
-
October 10th, 2018, 03:22 #881
The gp =/= GP issue is actually symptomatic of a larger issue relating to currency conversion. Yes, we all know that 1gp is the same as 1GP, but to a computer they are as different as $1 being the same/different as 1gp.
I am working (slowly) on a new Extension (called the DOE: WMC - Weights, Measurements & Currencies) that will solve this issue and thus all the issues around currency-conversion, giving change, etc - but I kept getting dragged off onto other things that other people want done "now".
The rounding issue is also being worked on - its an issue with the way computers store fractional numbers, and thus integral to the FG Engine. Still, we'll see what we can do.
TL;DR: its coming, but people are just going to have to be patient - I'm only one guy and there's only 24 hours in a day (and, for the record, my health isn't 100% at the moment - my issue, but it effects my productivity ).Dulux-Oz
√(-1) 2^3 Σ Π
...And it was Delicious!
Alpha-Geek
ICT Professional
GMing Since 1982
NSW, Australia, UTC +10
LinkedIn Profile: www.linkedin.com/in/mjblack
Watch our games on Twitch: www.twitch.tv/dulux_oz
Support Me on Patreon: www.patreon.com/duluxoz
Past Games, etc, on my YouTube Channel: www.youtube.com/c/duluxoz
-
October 10th, 2018, 04:27 #882
-
October 10th, 2018, 20:04 #883
Hmm, I'd rather say it's a symptom of the implementation chosen. Your answer ignores both fixed point representations and rational number implementations either of which is a much better format for currency. Someone back in the day decided these values were floating point and this is the consequence. You may have guessed, but I don't really like floating point numbers. There are lots of applications where they are a sub-optimal solution. Currency happens to be one of those applications.
Sorry to hear that, get well soon.
-
October 11th, 2018, 02:44 #884
Dulux-Oz
√(-1) 2^3 Σ Π
...And it was Delicious!
Alpha-Geek
ICT Professional
GMing Since 1982
NSW, Australia, UTC +10
LinkedIn Profile: www.linkedin.com/in/mjblack
Watch our games on Twitch: www.twitch.tv/dulux_oz
Support Me on Patreon: www.patreon.com/duluxoz
Past Games, etc, on my YouTube Channel: www.youtube.com/c/duluxoz
-
October 11th, 2018, 03:31 #885
- Join Date
- Jun 2013
- Location
- Isanti, MN
- Posts
- 2,922
Try using this:
Code:function round(num, numDecimalPlaces) local mult = 10^(numDecimalPlaces or 0) return math.floor(num * mult + 0.5) / mult end
-
October 11th, 2018, 09:16 #886
I haven't tried it, but I don't think that will help. It is more likely that the problem is that 0.2 is not representable exactly in this floating point representation. You will likely end up with 0.2000000098023, which is the closest this floating point representation can get to 0.2
This needs a fix in the output layer. The real underlying problem is that lua doesn't have an integer type. Actually, I have no idea what the problem is :-)
It's also possible that lua has been compiled with single precision floating point numbers here. Anyway, I'm sure Dulux-Oz is aware of all this and taking it into account while looking for a "decent solution".Last edited by Ampersandrew; October 11th, 2018 at 09:31.
-
October 11th, 2018, 17:35 #887
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,539
Yes, the Lua engine uses floating points internally for all numbers (and thus that is what the Lua scripts have to work with), which is the root of the situation.
Regards,
JPG
-
October 11th, 2018, 17:58 #888
- Join Date
- Jun 2013
- Location
- Isanti, MN
- Posts
- 2,922
Seems to work:
Code:local nTest = 1 / 6; Debug.console("Before round: " .. nTest); nTest = round(nTest, 2); Debug.console("After round: " .. nTest);
Code:Runtime Notice: Reloading ruleset Runtime Notice: s'Before round: 0.16666666666667' Runtime Notice: s'After round: 0.17'
Last edited by Andraax; October 11th, 2018 at 18:02.
-
October 13th, 2018, 19:54 #889
The solution Andrax listed is the method I have used for the problem of rounding.
The capitalization problem was resolved by having the routine ignore case.
Total Currency is first loaded into the extension and converted to copper,
then the transaction is conducted.
Then the resulting copper is consolidated to fewest coins using platinum as a base,
then reinserted into the record sheet.
The resulting vendor accurately transacts any exchange, giving proper change in return.
I have been using this for over 6 months with good results.
As the extension belongs to Dulux, I have not given the code to anyone.
I do not know what effect this code will have on other extensions, but expect
that Dulux will figure that out before incorporating it into his extension.
-
October 14th, 2018, 04:16 #890
Archangel
- Join Date
- Apr 2008
- Location
- Virginia Beach
- Posts
- 3,096
Intruder, he encourages people to modify his stuff and give him code in his extension threads. If you have the fix, I think he'd love to incorporate it.
Thread Information
Users Browsing this Thread
There are currently 2 users browsing this thread. (0 members and 2 guests)
Bookmarks