文本Ctrl->在 Erlang 中截断浮点数

发布于 2024-09-29 01:57:22 字数 435 浏览 0 评论 0原文

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

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

从 wxTextCtrl 生成一个错误,参数错误。

我知道这是罪魁祸首

NewGrossProfit = 5.45333,

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

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

-B

编辑

最后一个问题: 在 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

Last Question:
Truncate a float in Erlang

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

べ繥欢鉨o。 2024-10-06 01:57:22

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

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

应该有效。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文