在C的printf数字分组 [英] Digit grouping in C's printf
本文介绍了在C的printf数字分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要输出大量与千分隔符(逗号或空格) - 基本相同的如何显示3位分组但在C(GNU,99),使用的printf
数字。
I wish to output large numbers with thousand-separators (commas or spaces) — basically the same as in How to display numeric in 3 digit grouping but using printf
in C (GNU, 99).
如果printf的不支持数字原生分组,我怎么能与像的printf(%S,group_digits(编号))
?
If printf does not support digit grouping natively, how can I achieve this with something like printf("%s", group_digits(number))
?
它必须支持负整数和preferably花车了。
It must support negative integers and preferably floats, too.
推荐答案
如果您可以使用 POSIX的printf ,试试
#include <locale.h>
setlocale(LC_ALL, ""); /* use user selected locale */
printf("%'d", 1000000);
这篇关于在C的printf数字分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文