Skip to content
This repository was archived by the owner on Oct 30, 2022. It is now read-only.

ArthurClemens/parse_price

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

parse_price

Erlang utility. Reads price text (in various notations) and returns this as a data proplist.

The proplist contains the elements keys:

  • currency: (binary string) Currency symbols are returned as ISO 4217 Currency Codes. Note that coverage of currency codes is incomplete.
  • whole: (integer) The amount before the fraction.
  • fraction: (integer) The fraction.
  • text: (binary string) Price without currency. The "." (FULL STOP) indicates the decimal point.

Examples

parse_price:parse(<<"$ 1,222.9">>).
[{currency,<<"USD">>},{whole,1222},{fraction,90},{text, <<"1222.90">>}]
parse_price:parse(<<"EUR 108.75">>).
[{currency,<<"EUR">>},{whole,108},{fraction,75},{text, <<"108.75">>}]
parse_price:parse(<<"11,- €"/utf8>>).
[{currency,<<"EUR">>},{whole,11},{fraction,0},{text, <<"11.00">>}]

See the test file for full coverage.

Requirements

  • Erlang 17 or higher

Build

$ rebar3 compile

About

Reads price text (in various notations) and returns this as a data proplist.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages