On Dec 27, 3:54 am, Bill DeShields <[email protected]> wrote:
> I can find the average of numbers. What is the best way to round off a
> number like 19.3 to show just 3 or 19.7 to 20?
>

The java.lang.Math  class has static methods:
  public static int round(float x)
  public static long round(double x)

which round to the nearest integer/long as appropriate.

Alternatively, you can do it "by hand" by adding 0.5 and taking the
floor...it's what Math.round() does for you.  Probably best to use the
library method anyway, as it's already tested and known to work...and
people reading your code will recognise it more easily.

See that API documentation for Math: 
http://download.oracle.com/javase/6/docs/api/java/lang/Math.html


Good luck,
Stephen

-- 
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en

Reply via email to