partition_number(Number, Separator) ->
SepChar = hd(Separator),
NumStr = if
is_integer(Number) -> hd(io_lib:format("~B", [Number]));
is_float(Number) -> hd(io_lib:format("~f", [Number]));
true -> Number
end,
% If there is a decimal point, use that as the starting point
{ChgStr, Remain} = case regexp:first_match(NumStr, "\\.") of
{match,Start,Length} ->
{string:substr(NumStr, 1, Start - 1),
string:substr(NumStr,Start,string:len(NumStr))};
nomatch -> {NumStr, ""}
end,
{ok, Subs, _} = regexp:gsub(lists:reverse(ChgStr),
"([0-9][0-9][0-9])", "&" ++ Separator),
Final = case lists:nth(string:len(Subs), Subs) of
SepChar -> string:substr(Subs, 1, string:len(Subs) - 1);
_ -> Subs
end,
lists:reverse(Final) ++ Remain.
|