zbrox / iso_currency Goto Github PK
View Code? Open in Web Editor NEWISO 4217 currency codes for Rust
License: MIT License
ISO 4217 currency codes for Rust
License: MIT License
The latest version of the ISO official dataset includes another Venezuelan bolívar Soberano.
The latest version of the ISO official dataset includes another Sierra Leonean leone.
Currencies according (according to locale) place the symbol either in front of the amount, at the end, or between (instead of the decimal separator).
Hello,
I think serde support would be nice.
Most currencies are missing their centesimal symbols
Hi there,
Thanks for your work on this crate!
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 |
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).
exponent
instead of subunits_fraction
exponent()
getter functionsubunits_fraction()
to return the result of 10_u16.pow(minor_units)
PR on the way 🚀
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.
Problem statement: I want to parse an API where the casing convention doesn't match the one in the crate.
A suggested fix: Serde already has attributes to customize casing. They would only need to be exposed in the crate.
is there an iterator over all currencies?
Is it possible to generate strings formatted in that currency?
Some symbols have a representation in English
This might be more handy to use iso_countries instead of plain old str for Currency::used_by
, this way we can also add a function to get currencies used by a specific country ?
I don't know if I have enough information to decide on some of the symbols and what is predominantly used. Maybe alternatives (where existing) should be included in the CurrencySymbol struct.
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.
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
-> AustraliaCHF
-> SwitzerlandDKK
-> DenmarkGBP
-> UKILS
-> IsraelINR
-> IndiaMAD
-> MoroccoNOK
-> NorwayNZD
-> New ZealandUSD
-> USAZAR
-> South AfricaThe 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
.
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.