paupino / rust-decimal

Decimal number implementation written in pure Rust suitable for financial and fixed-precision calculations.
https://docs.rs/rust_decimal/
MIT License
972 stars 177 forks source link

Introduce wasm_bindgen support and expose a toNumber method for use in JavaScript #614

Closed ChristianIvicevic closed 6 months ago

ChristianIvicevic commented 10 months ago

I've been exploring potential implementations and would like to discuss an initial, lightweight contribution. Instead of fully binding and exporting the entire crate, my intention is to simplify it by exporting the Decimal type to JavaScript and making it possible to map it to a number type. I don't anticipate performing operations on Decimals from the JavaScript side.

To achieve all of this, I've added a conditional attribute to the Decimal struct and introduced two methods within a conditional module, Decimal::to_number and Decimal::from_number, inspired by decimal.js.

Fixes #613

paupino commented 9 months ago

Thank you for putting this together - it's looking very complete for a new feature! We'll need to play a little bit to get this working with CI. It'll likely be failing on the build all features step - unfortunately the step is required for documentation generation so I'll need to think about how to skirt around this (or whether it's still necessary).

ChristianIvicevic commented 9 months ago

Thank you for putting this together - it's looking very complete for a new feature! We'll need to play a little bit to get this working with CI. It'll likely be failing on the build all features step - unfortunately the step is required for documentation generation so I'll need to think about how to skirt around this (or whether it's still necessary).

Okay cool. Since I haven't been coding a lot in my free time lately, I haven't fully explored whether I'm fully happy with the from_number function given it is fallible at the moment. Once I've confirmed I'm happy with the exposed API I can promote this draft to a full PR then we can explore the CI errors.

ChristianIvicevic commented 9 months ago

@paupino Just wanted to drop by and mention that I will not have time to finish this in the near future and plan to spend some time on it after Christmas at which point I can invest time to rebase and tweak the API properly.

ChristianIvicevic commented 6 months ago

Due to a minor conflict with an app of mine that depends on my personal fork I had to open an independent new PR #650 that provides the feature.