T
T
Tolik2014-08-03 18:25:25
C++ / C#
Tolik, 2014-08-03 18:25:25

How can I make printf print a number of the same length regardless of its sign?

That is, I print %.5d and all numbers are the same length. But if this number is less than zero, then the whole system is shifted due to the minus. Whether it is possible to make that for example for positive it was displayed plus? Or something like that?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2014-08-03
@Diel

A space after the % puts a space before positive values, at the position where the minus goes before negative ones: "% .5d". Plus after % puts a sign before both positive and negative values: "%+.5d". You can learn about this and much more in man 3 printf .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question