String.format() get maximum value

I implemented a counter method that returns always an incremented number. But the user can give wished [format][1], 2 digits, 3 digits or whatever he wants. The format is the standard String.format() type of String like `%02d` or `%5d`. When the maximum value is reached, the counter should be reset to 0. **How can I find out the max value that can be represented with the given [format][2]?** int counter = 0; private String getCounter(String format){ if(counter >= getMaximum(format)){ counter = 0; } else { counter++; } return String.format(format, counter); } private int getMaximum(String format){ //TODO ??? //Format can be %02d => should return 100 //Format can be %05d => should return 100000 } [1]: http://docs.oracle.com/javase/6/docs/api/java/util/Formatter.html#syntax [2]: http://docs.oracle.com/javase/6/docs/api/java/util/Formatter.html#syntax

以上就是String.format() get maximum value的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏