如何根据 Haskell 中的区域设置格式化数字?
在 Python 中,我可以使用 locale.format
根据语言环境设置漂亮地打印数字:
>>> import locale
>>> locale.setlocale(locale.LC_ALL, "en_US.UTF-8")
'en_US.UTF-8'
>>> locale.format("%.2f",1234567.89,grouping=True)
'1,234,567.89'
How can I do the same in Haskell?我看到有 localeconv 和 setlocale 绑定,但是是否有一个通用的漂亮打印机尊重 Lconv
?
In Python I can use locale.format
to pretty-print numbers according to locale setting:
>>> import locale
>>> locale.setlocale(locale.LC_ALL, "en_US.UTF-8")
'en_US.UTF-8'
>>> locale.format("%.2f",1234567.89,grouping=True)
'1,234,567.89'
How can I do the same in Haskell? I see that there are localeconv and setlocale bindings, but is there a generic pretty printer which respects Lconv
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想说,如果缺少相关库,那么您可以自己编写一个(明显的选择,并不容易)或为所需的函数编写一个绑定。例如,
sprintf
的受限绑定只允许 sprintf 进行双打:Double.hs:
double.h:
double.c:
构建为:
I would say that if the library in question is missing then you could either write yourself one (obvious option, not easy) or write a binding for the needed function. For example, restricted binding for
sprintf
which allows to sprintf only doubles:Double.hs:
double.h:
double.c:
Build as: