Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to handle DecimalFormat overflow?

 
Ben Ethridge
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, all.

I was a bit surprised that this gave no overflow exception, and that java happily expands pattern to accept a too-large number, and that I have to, say, resort to comparing the length() of output to the length() of pattern, and create a custom exception if output "overflows".

Resorting to this seems a bit inelegant. After all, this is a concrete subclass of NumberFormat which is all about formatting numbers for display and reports and such, where field lengths matter quite a lot.

Is there anything in NumberFormat or its cousins that traps for overflowing numbers?



Ben Ethridge
SCJP 1.4
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there anything in NumberFormat or its cousins that traps for overflowing numbers?


No...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic