Domanda

I need to seperate digit from sign. So, if I have digit 2635, I need it to be like this:

"+       2635."

Here is my code:

printf("%+-#13.4g\n", digit);

and what I'm getting is

"+2635.       "
È stato utile?

Soluzione

Maybe you're looking for a simpler answer, but in a pinch you can do this:

printf("%c%#13.4g\n", digit < 0 ? '-' : '+', fabs(digit));
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top