开发者

TextCtrl -> Truncate a float in Erlang

My last question leads me to this one:

wxTextCtrl:setValue( TcGrossProfit, io_lib:format("~.2f",[NewGrossProfit])),

generates an error from wxTextCtrl, with a bad arg.

I know this is the culprit

NewGrossProfit = 5.45333,

io_lib:format("~.2f",[NewGrossProfit])

Thanks for the last one, hope this one's easier

-B

EDIT开发者_JAVA百科

Last Question: Truncate a float in Erlang


The problem is that io_lib:format("~.2f",[NewGrossProfit]) returns an iolist: ["5.45"], but wxTextCtrl:setValue seems to need a string ("5.45"). So

wxTextCtrl:setValue( TcGrossProfit, lists:flatten(io_lib:format("~.2f",[NewGrossProfit])))

should work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜