Giter VIP home page Giter VIP logo

currency_rs's People

Contributors

ryiski avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

currency_rs's Issues

Poor performance casued by fancy-regex

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)

Implementations of std::ops traits (Add/Sub/etc)

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.

`set_precision` doesn't remove 0s, so `set_from_cents` + `set_precision(0)` does not format correctly

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.