% (converting a negative number to a positive in System.out.printf

Output of this code

System.out.printf("%d %(d %+d %05d\n", 3, -3, 3, 3); 

there is

 3 (3) +3 00003 

Can someone explain why in this statement 3 is displayed as 3?

+4
source share
2 answers

Can someone explain why in this statement 3 is displayed as 3?

He is not, he is printed as (3)

From Javadoc for Formatter, say the flag (

Result encloses negative numbers in parentheses

+9
source

Formatter help says that the format "(" means that it encloses negative numbers in parentheses.

In accounting, debt amounts are often represented in red numbers or a number in parentheses, as an alternative designation for representing negative numbers.

From Wikipedia: Negative Numbers

+9
source

Source: https://habr.com/ru/post/1438231/


All Articles