开发者

TextCtrl -> Truncate a float in Erlang

开发者 https://www.devze.com 2023-01-22 07:26 出处:网络
My last question leads me to this one: wxTextCtrl:setValue( TcGrossProfit, io_lib:format(\"~.2f\",[NewGrossProfit])),

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

精彩评论

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