# Rounding calculations

• 08-20-2011, 01:26 PM
lynxbci
Rounding calculations
Hi,

I have a formula that peforms a calculation, and as the inputs are double, the calc is too.
Code:

```private double calcpoints(float input_pr, float input_ca, float input_fa, float input_fi) {                 return ((input_pr / 10.9) + (input_ca / 9.2) + (input_fa / 3.9) + (input_fi / 35));```
However, this return 7.8443242 and i want it to return 8 (rounded value)
How do i do this please?

thanks
• 08-20-2011, 01:41 PM
Fabken
Hello Lynxbci, there is a round method in the java.lang.math library.

Fabrice
• 08-20-2011, 01:47 PM
Fabken
float test = (float) 2.45;
long testRound= Math.round(test);

this is how you use it.
• 08-20-2011, 01:55 PM
lynxbci
Thanks very much all working ok
• 08-20-2011, 02:50 PM
RPFeltz
Perhaps converting it to an int value works too.
double test = 7.82562;
int rounded = (int) test;
• 08-20-2011, 02:58 PM
R-J
Quote:

Originally Posted by RPFeltz
Perhaps converting it to an int value works too.
double test = 7.82562;
int rounded = (int) test;

That will round everything between a 7 and an 8 to a 7.
• 08-20-2011, 03:14 PM
RPFeltz