-2

I have a double in my Java code that could be very small or very large. I have been trying to find way to round that double to an appropriate amount so that I can display it nicely to the user. For example:

0.001 // Rounds to 0.001
0.100001 // Rounds to 0.1
35.00000001 // Rounds to 35

Is there a way to achieve this in Java?

1 Answers1

1

This question was already answered here: How do I format a number in Java?

DecimalFormat() is what you are looking for.