Truncate a float in Erlang

I am using a function to create a list from a float.


It returns:


I need it to give me a number exactly like:


If I fed it 5.23


If I fed it 5.5


So basically the number rounded to two decimal places. Probably an easy fix.



I would like to use the io format it looks like it might work,

but it dosen't in this example:

wxTextCtrl:setValue( TcGrossProfit, io:format("~p", [NUMBER]), ),

seems textctrl wants a string, I don't want to print it to the screen.


  • Are you looking for something like this:

    6> F = 5/2.
    7> io_lib:format("~.1f",[F]).
    8> io_lib:format("~.2f",[F]).
    9> io_lib:format("~.3f",[F]).

    If yes, have a look at the io_lib module.