Giter Club home page Giter Club logo

iso_currency's People

Contributors

b4d8 avatar daniel1of1 avatar dependabot[bot] avatar icandivideby0 avatar jacobsvante avatar laynor avatar richardpringle avatar zbrox avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

iso_currency's Issues

Subunits fraction are not always correct

Hi there,

Thanks for your work on this crate!

Problem

ISO official data provides the number of minor units for most of the listed currencies which is actually an exponent because all listed currencies are base 10 for both their major and minor unit.

The subunits_fraction should then be be the result of 10 ^ exponent but this is not currently the case for 19 currencies (taking aside the 2 special cases detailed below).

alpha2 current actual
BIF 100 1
CLF 100 10000
CLP 100 1
DJF 100 1
GNF 100 1
ISK 100 1
JOD 100 1000
JPY 100 1
KMF 100 1
KRW 100 1
MGA 5 100
MRU 5 100
PYG 100 1
RWF 100 1
UGX 100 1
UYI 100 1
UYW 100 10000
VND 10 1
XAF 100 1
XOF 100 1
XPF 100 1

Edge case

Malagasy ariary (MRU) and the Mauritanian ouguiya (MGA) are technically divided into 5 subunits. If they have a face value of "1/5", these are not used in practice. When written out, a single significant digit is used (example: 1.2 UM so that 10 UM = 1 MRU). -- Source Wikipedia.

While those are currently registered by the crate as having 5 subunits_fraction, IMHO I believe they should be updated to match ISO definition and actual usage (which is a breaking change).

Solution

  • update the internal dataset with exponent instead of subunits_fraction
  • add exponent() getter function
  • update subunits_fraction() to return the result of 10_u16.pow(minor_units)

PR on the way 🚀

Maybe numeric currency codes should be strings

Numeric codes are zero-padded and maybe there's no use for them to be integers and should be just strings. They would most likely be used as strings when having to match against them in a potential use of the library.

Proposal: get Currency from Country

A nice addition would be to be have the inverse of used_by(), something like:

/// Returns a vector of the currencies a country is known to use
fn from_country(country: Country) -> Option<Vec<Currency>> {}

/// Constructor for Currency based on a best guess from a Country
fn guess_from_country(country: Country) -> Option<Self> {}

The later is kind of like ICU likely subtags but would require to rework on the data.

Proposal: get Country from Currency

From the data exploration in #19, I figured could easily further provide:

/// Returns a vector of the countries a currency is known to be used in
fn countries(&self) -> Option<Vec<Country>> {}

/// Return a single Country based on a best guess
fn guess_country(&self) -> Option<Vec<Country>> {}

For the later, we only have to handle the 19 currencies with more than 1 country.

In my opinion, 13 of them actually resolve quite naturally:

  • AUD -> Australia
  • CHF -> Switzerland
  • DKK -> Denmark
  • GBP -> UK
  • ILS -> Israel
  • INR -> India
  • MAD -> Morocco
  • NOK -> Norway
  • NZD -> New Zealand
  • USD -> USA
  • ZAR -> South Africa

The 6 remaining (ANG, EUR, XAF, XCD, XOF and XPF) do require an opinionated guess which could be solved by returning None or the first Country in logical order.

We could also suggest that iso_country provide reciprocal from_currency and from_currency_guess impl on Country.

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.