TextCtrl - >在Erlang中截断一个浮点数

BAR*_*BAR 1 floating-point erlang new-operator

我的最后一个问题让我想到了这个:

wxTextCtrl:setValue( TcGrossProfit, io_lib:format("~.2f",[NewGrossProfit])),
Run Code Online (Sandbox Code Playgroud)

使用错误的arg从wxTextCtrl生成错误.

我知道这是罪魁祸首

NewGrossProfit = 5.45333,

io_lib:format("~.2f",[NewGrossProfit])
Run Code Online (Sandbox Code Playgroud)

感谢最后一个,希望这个更容易

-B

编辑

最后一个问题: 在Erlang中截断一个浮点数

Ale*_*nov 5

问题是io_lib:format("~.2f",[NewGrossProfit])返回一个iolist : ["5.45"],但wxTextCtrl:setValue似乎需要一个字符串("5.45").所以

wxTextCtrl:setValue( TcGrossProfit, lists:flatten(io_lib:format("~.2f",[NewGrossProfit])))
Run Code Online (Sandbox Code Playgroud)

应该管用.