问题
java.util.logging.Logger class provides ability to use such a syntax:
int i=0;
log.log(Level.INFO,"int i = {0}", i);
This will print out "int i = 0". Unfortunately when I have a bigger value, like 9093, it will print out "int i= 9,023" separating each 3 digits with comma.
The question is how should I get rid of thoose commas? Preferably changing insides of {}. Tried both {0:d} and {0:%d}. Both didnt help. Is it even possible to control parametres like this? Or should I convert my int to string myself?
回答1:
It seems the second parameter is a MessageFormat
which supports "sub-formats". Try
log.log(Level.INFO, "int i = {0,number,#}", 1234567);
This eliminates grouping characters for me.
See http://docs.oracle.com/javase/7/docs/api/java/text/MessageFormat.html and http://docs.oracle.com/javase/7/docs/api/java/text/DecimalFormat.html (number sub-formats are interpreted as DecimalFormat
).
来源:https://stackoverflow.com/questions/20749130/java-java-util-logging-logger-using-array-objects-as-arguments