How can i round a double to a specific decimal point?
Printable View
How can i round a double to a specific decimal point?
I searched for an hour and couldnt find a inlined way of using a specific method, I think you have to create one as well.
A simple modification to what virtual started with would be to, in that function convert the double to a string, then get the length of that and check against the desired number of significant digits, such as wanting to round to the nearest thousdanth, when the double only goes to the tenth.
Depending on what this is used for also, you may want to check for the machine epilson of the machine you are on, to see where the machine's actual boundary is for numbers. This would be overkill if this round feature is not used for heavy numerical computation.
Thanks for the help guys. I got it to work really simply by using java.text.DecimalFormat.
I can go into details if you are curious.:D
nice, i didnt think of that