I can't find the answer in teh Googles or SO, and it's annoying me.
Reading the javadocs , I find " If there is an explicit negative subpattern, it serves only to specify the negative prefix and suffix; the number of digits, minimal digits, and other characteristics are all the same as the positive pattern. That means that "#,##0.0#;(#)" produces precisely the same behavior as "#,##0.0#;(#,##0.0#)"." However, this code does not seem to follow with that:
import java.text.DecimalFormat;
public class NumberFormatTest {
public static void main(String args[]) {
DecimalFormat df = new DecimalFormat("#,###;(#,###)");
System.out.println(df.format(-1234.0));
df.applyPattern("#,###;(#)");
System.out.println(df.format(-1234.0));
}
}
give an output of
(1,234)
(1,234
(note the missing paren in line 2)
What am I missing?
Bug in DecimalFormat. See bug report http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6609740
Try something
DecimalFormat df=new DecimalFormat("#,##0.0");
System.out.println(df.format(-12999.0));// the output is: -12 999,0
This is working
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.