WIP: Add formatter and some other stuff
This commit is contained in:
@@ -1048,37 +1048,3 @@ do_grids_mess_sig2(Request = #{"grids" := 1,
|
||||
wxDialog:destroy(Dialog);
|
||||
do_grids_mess_sig2(BadRequest, _) ->
|
||||
tell("Bad request: ~tp", [BadRequest]).
|
||||
|
||||
|
||||
|
||||
|
||||
%%% Helpers
|
||||
|
||||
|
||||
price_to_string(Pucks) ->
|
||||
Gaju = 1_000_000_000_000_000_000,
|
||||
H = integer_to_list(Pucks div Gaju),
|
||||
R = Pucks rem Gaju,
|
||||
case string:strip(lists:flatten(io_lib:format("~18..0w", [R])), right, $0) of
|
||||
[] -> H;
|
||||
T -> string:join([H, T], ".")
|
||||
end.
|
||||
|
||||
string_to_price(String) ->
|
||||
case string:split(String, ".") of
|
||||
[H] -> join_price(H, "0");
|
||||
[H, T] -> join_price(H, T);
|
||||
_ -> {error, bad_price}
|
||||
end.
|
||||
|
||||
join_price(H, T) ->
|
||||
try
|
||||
Parts = [H, string:pad(T, 18, trailing, $0)],
|
||||
Price = list_to_integer(unicode:characters_to_list(Parts)),
|
||||
case Price < 0 of
|
||||
false -> {ok, Price};
|
||||
true -> {error, negative_price}
|
||||
end
|
||||
catch
|
||||
error:R -> {error, R}
|
||||
end.
|
||||
|
||||
Reference in New Issue
Block a user