localizationerlangcurrencychicagoboss

currency localization in erlang?


I have an amount like 10 digits "1234567328.899" I want to show as currency with commas in it like this:.

"$1,234,567,328.899". 

I had written a standalone module to do that, it was working

partition_float(N,P,FP,L) ->
    F = tl(tl(hd(io_lib:format("~.*f",[L,N-trunc(N)])))),
    lists:flatten([partition_integer(trunc(N),P),FP,F]).

partition_float(Data, $,, $., 6).%% Where Data is ["1234567328.899", ""1217328.89", "67328", ...]

It was running successfully as a stand alone but when insert to the project of a chicagoboss, It's throwing following error.

[{"c:/Users/Dey/InheritanceTax/inheritance_tax/src/lib/data_util.erl",[{575,erl_lint,{call_to_redefined_old_bif,{trunc,1}}},{576,erl_lint,{call_to_redefined_old_bif,{trunc,1}}}]}]

Solution

  • -module(amt).
    -export([main/0]).
    
    format(S, Acc, M) ->
        try 
            Str = string:substr(S, 1, 3),
            Str1 = Str ++ ",",
            Str2 = string:substr(S, 4),
            format(Str2, Acc ++ Str1, M),
            ok
        catch
            error:_Reason ->
                % io:format("~p~n", [Reason]),
                io:format("~p", [lists:reverse(Acc ++ S ++ "$") ++ "." ++ M])
        end.
    
    disp(N) ->
        [L,M] = string:tokens(N, "."),
        format(lists:reverse(L), "", M).
    
    main() -> disp("1234567328.899").   % "$1,234,567,328.899"ok