By default, printf() displays negative numbers with a minus (-) symbol in front of them.
By default it doesn't put a plus (+) symbol in front of positive numbers.
To always display a sign symbol, use the sign specifier, +, in front of the type specifier.
Here's an example:
<?php printf("%d \n ", 123 ); // Displays "123" printf("%d \n ", -123 ); // Displays "-123" printf("%+d \n ", 123 ); // Displays "+123" printf("%+d \n ", -123 ); // Displays "-123" ?>//from w ww . j a v a2 s .co m