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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With