Round to nearest decimal

84 views
Skip to first unread message

rama

unread,
Mar 18, 2010, 7:37:43 AM3/18/10
to Selenium Users
Hi

Am using Selenium RC with Junit+Eclipse Framework. One of my script
working on calculations, which should return the 2 digit decimal
number after rounding. But its not considering the 3rd digit to round
the number. I am a tester with basic java skills. Any help is
appreciated.

vat=roundTwoDecimals(sub_cost*17.50/100.00);


public double roundTwoDecimals(double d)
{
DecimalFormat twoDForm = new DecimalFormat("#.##");
return Double.valueOf(twoDForm.format(d));
}


Thanks
Rama

RITESH MAHAJAN

unread,
Mar 18, 2010, 8:06:21 AM3/18/10
to seleniu...@googlegroups.com
Hi,

This code only round the number on the basis of third digit after decimal point.
Ex

12.236 will change to 12.24 (rounding second digit on the basis of 3 digit)
12.299 will change to 12.3 (as after rounding 9 it changes to 10 so next number will round and so that 2 is replace by 3).

Thanks
Ritesh



--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.




--
Ritesh Mahajan

rama

unread,
Mar 18, 2010, 8:41:51 AM3/18/10
to Selenium Users
Ritesh,

But its not rounding the number based on 3rd digit, simply returning
12.23 / 12.29. Is there any workaround to return the numbers as you
mentioned?

Thanks
Rama

> > selenium-user...@googlegroups.com<selenium-users%2Bunsubscribe@go­oglegroups.com>


> > .
> > For more options, visit this group at
> >http://groups.google.com/group/selenium-users?hl=en.
>
> --

> Ritesh Mahajan- Hide quoted text -
>
> - Show quoted text -

RITESH MAHAJAN

unread,
Mar 18, 2010, 8:49:24 AM3/18/10
to seleniu...@googlegroups.com
I checked this code, using simple java code, Do one thing, execute this ode from eclips
 public static void main(String a[])

  {
    DecimalFormat twoDForm = new DecimalFormat("#.##");
    System.out.println(Double.valueOf(twoDForm.format(12.239)));
  }
Run as java application

this will give you 12.24, I think there is no issue with this code, may be somthing other

Thanks
Ritesh

To unsubscribe from this group, send email to selenium-user...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.




--
Ritesh Mahajan

rama

unread,
Mar 18, 2010, 9:00:26 AM3/18/10
to Selenium Users
yes u r right. Thank you. I will try to trace the problem
Reply all
Reply to author
Forward
0 new messages