ryiski / currency_rs Goto Github PK
View Code? Open in Web Editor NEWA rust library for handling currencies
License: MIT License
A rust library for handling currencies
License: MIT License
While trying to make a rfm report with 40_000 objects it took 40+ secs to finish it.
After a little digging around found out fancy-regex was the perpetrator.
SOLUTION('s)?
1 - create them at runtime using lazy_static
2 - in some cases, it requires to be dynamic, so maybe create a function and use this to cache them
3 - a mix of 1 and 2
3 - Look for another crate that supports lookahead and lookbehind (most likely no one else)
Is your feature request related to a problem? Please describe.
When dealing with currency in Rust code, it's often necessary to do operations (e.g. adding/subtracting) on multiple parsed values.
Describe the solution you'd like
Implement the traits from std::ops
that make sense to use with Currency
, in particular Add
, AddAssign
, Sub
, SubAssign
, Mul
and MulAssign
(Div
might be more tricky due to remainder issues).
This allows Currency
values to be added using the built-in operators, e.g. Currency::new_float(2.51, None) + Currency::new_float(2.51, None)
.
Describe alternatives you've considered
The built-in add
/ subtract
/ multiply
/ divide
functions can be used to do operations with f64
values, but if the values are already parsed as Currency
they would need to be converted back to f64
first.
I pass a format function the value in cents, or more accurately, in hundreds since e.g. JPY don't really do subunits.
But I have to deal with multiple currencies, so I do:
let value = 100.0;
let otp = CurrencyOpts::new()
.set_from_cents(true) // The data I have is in centi units, so, from cents is true
.set_precision(0) // Japanese yen aren't actually fractional
.set_symbol("¥");
Currency::new_float(value, Some(otp))
The expected outcome is that because of set_from_cents
is true, this will calculate that I have 1 yen, and then because precision is at 0, it will display ¥1
rather than ¥1.00
.
Instead, it still displays the latter, but without the dot - e.g. ¥100
.
If I set precision to 1, it displays ¥10.0
which is also incorrect, it should be ¥1.0
Either set_from_cents
does not calculate the value to correctly be 1.00
or set_precision
does not format the currencty correctly, or both.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.