Thread: DOE: Locations Extension
-
October 10th, 2018, 20:04 #881
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 #882
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 #883Celestial Paragon
- Join Date
- Jun 2013
- Location
- Isanti, MN
- Posts
- 2,682
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 #884
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 #885SmiteWorks
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 23,405
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 #886Celestial Paragon
- Join Date
- Jun 2013
- Location
- Isanti, MN
- Posts
- 2,682
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 #887
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 #888

Archangel
- Join Date
- Apr 2008
- Location
- Virginia Beach
- Posts
- 3,093
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.
-
October 14th, 2018, 04:30 #889Banned
- Join Date
- Mar 2018
- Location
- Sol3
- Posts
- 374
Same, because merchants can also act as money lenders. or just round up and things are all dollars to make them whole numbers
copper = 1, silver = 10, gold... etc
sure people are n longer carrying 30k copper piece around, but nobody tracks weights once they get to town with it these days
-
October 14th, 2018, 14:01 #890
my DM track
Shadzar
KICK| TWITCH | YOUTUBE
BRAZILIAN
GMT-3
FANTASY GROUNDS UNITY - ULTIMATE VERSION
PLAYER ONLY
FORGE CREATOR
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)


Reply With Quote

Bookmarks