简体   繁体   中英

A DecimalFormat pattern for a single digit between 1-9

I'm writing a Sudoku board in Java and opted to use the JFormattedTextField class for the board cells because I can have a control about the input with providing a correct DecimalFormat object.

My question is, what String should I use in the constructor of the DecimalFormat so that it would represent a pattern of a single digit between 1-9.

Alternatively, is there a better class(es) to use for that purpose?

Thanks

    String pattern = "#";
    DecimalFormat decimalFormat = new DecimalFormat(pattern);
    decimalFormat.setMaximumIntegerDigits(1);      
    String format = decimalFormat.format(number);

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM