I have open sourced and published my fixed-point decimal library to MOPS: https://mops.one/decimal
It provides a Decimal Motoko type, conversion to/from Text, Float, Int and Nat with rounding, arithmetic functions add, subtract, multiply, divide, power and several other utility functions.
I developed this as part of our cross-chain DeFi project daemoney (I’ll be sharing more on this very soon!). The use case was the requirement to predictably and reproducibly parse, represent, display, and cross-multiply and -divide values of currencies with differing numbers of decimals (e.g. e8s, sat, wei, USD). I couldn’t find any existing fixed-point decimal type available to use in Motoko, so developed this and now very pleased to share.
I hope you find it useful - let us know if you do, and how you’re using it.
Heh yes some of that GPT analysis was flawed, especially the argument about rounding! It did point out that fromText(“-”) parses to 0 - I’m not happy with that as it could mask errors in the input data so have fixed it to parse to #InvalidInput.
I made couple of other tweaks and added JSON output - version 3.0.1 is now published to MOPS.