Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要将数字与符号分开。所以,如果我有数字 2635,我需要它是这样的:
“+ 2635。”
这是我的代码:
printf("%+-#13.4g\n", digit);
我得到的是
“+2635。”
也许您正在寻找一个更简单的答案,但在紧要关头您可以这样做:
printf("%c%#13.4g\n", digit < 0 ? '-' : '+', fabs(digit));