FileDocCategorySizeDatePackage
Round.javaAPI DocExample677Sat Nov 25 12:56:06 GMT 2000None

Round

public class Round extends Object
Demonstrate our own version round().
author
Ian F. Darwin, ian@darwinsys.com
version
$Id: Round.java,v 1.2 2000/11/25 17:56:06 ian Exp $

Fields Summary
public static final double
THRESHOLD
We round a number up if its fraction exceeds this threshold.
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] argv)

		for (double d = 0.1; d<=1.0; d+=0.01)
			System.out.println(d + "-> " + round(d));
	
static longround(double d)

	/* Return the closest long to the argument.
	 * ERROR CHECKING OMITTED.
	 */
	    
		long di = (long)Math.floor(d);	// integral value below (or ==) d
		if ((d - di) > THRESHOLD)
			return di + 1;
		else return di;