on 12-20-2010 2:08 PM
Hi
I have taken an attribue of type double and on performing some operation the values are coming upto 8 decimal places. I want that it should come only upto 2 decimal places.
Thanks
Saurabh
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Saurabh,
Try the below code,
DecimalFormat myDecimalFormat = new DecimalFormat("###.##");
Double formatedNum = Double.parseDouble(myDecimalFormat.format(num));
If num is the resulting double value after some mathametical operation then formatedNum will be its equivalent value with only two decimal places.
Regards,
Vishweshwara P.K.M
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Saurabh,
you should use round off functionality of java like Round(num,2)
Regards,
Sen
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
89 | |
10 | |
9 | |
9 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.