Skip to content

Instantly share code, notes, and snippets.

View mlersch's full-sized avatar
🍌
coding

Matthias Lersch mlersch

🍌
coding
View GitHub Profile
@mlersch
mlersch / currency.erl
Last active February 5, 2018 18:19
A Erlang snippet to convert a currency strings or binary to a integer
-author("mlersch").
-module(currency).
-export([test/0, convert/1]).
convert(V) when is_binary(V) -> convert(binary_to_list(V));
convert(V) when is_float(V) -> round(V*100);
convert(V) when is_integer(V) -> V*100;
convert(V) when is_list(V) ->
V1 = re:replace(re:replace(V, "[^0-9 ^, ^.]", "", [{return,list},unicode,global]), "\\h", "", [{return,list},global]),