質問

What is the use of the negative pattern?

NumberFormat nf = NumberFormat.getPercentInstance(Locale.ITALY);
DecimalFormat df = (DecimalFormat)nf;
df.applyPattern("###,###.###;(###,###.###)");
System.err.println(df.format(-12.45));//output (12,45);

In what scenario would it be useful? Isn't just a module?

役に立ちましたか?

解決

The negative pattern is simply a different way to print out negative numbers. You may want a wide variety of choices:

 1,234       1,234         1,234        1,234 CR
-1,234       1,234-       (1,234)       1,234 DR

and so on. Each of these is useful in their different domains. The (1,234) variant is actually quite useful if you don't have a colour printer since it stands out a lot more than just a leading negative and it's used quite a bit in bookkeeping and accounting areas.

My own favorite (in a non-Java setting, Libre Office) is:

"#,##9.99 ;[RED](#,##9.99-)"

which outputs the negative numbers in red with a trailing - sign and surrounded by parentheses, so there's no doubt it's a negative value:

enter image description here

他のヒント

Believe it or not that I've seen multiple business applications that format their negative values in exactly this manner. So I'm afraid the use is because people need/use it.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top