MAth floor method

Please help... I am trying to write an applet that has the following four methods for rounding a number x in various ways:

1. roundToInteger( double number ) double y = Math.floor ( X )

2. roundToTenths( float number ) float y = Math.floor ( X ) / 10

3. roundToHundredths( double number ) double y = Math.floor ( X ) / 100

4. roundToThousandths( double number ) double y = Math.floor ( X ) / 1000

if I am populating the code via user input I will have to use the parse function, for example:

String InputasString = JOptionPane.showInputDialog("Message");

int InputasInteger = Integer.parseInt (Input);

I believe this works for any data type...wouldn't it?

but how do i write an applet with error conditions and

[778 byte] By [xoxo123a] at [2007-11-27 3:54:05]
# 1

Di you mean error conditions when the user inputs something that can't be parsed as an int? That's what try/catch does.String inputAsString = JOptionPane.showInputDialog("Message");

try {

int inputAsInteger = Integer.parseInt (inputAsString);

// inputAsInteger will be a proper int here

// ...

} catch(NumberFormatException nfe) {

// Here you do whatever you want when the user

// has entered bad data

}

(I've changed your variable names a little.)

In your rounding methods do you mean for 2->4 to significantly change the number being rounded? Most people wouldn't regard this as rounding. Or perhaps you mean something along the lines of (10*x)/10 etc.

pbrockway2a at 2007-7-12 8:58:11 > top of Java-index,Java Essentials,Java Programming...
# 2
oknull
xoxo123a at 2007-7-12 8:58:11 > top of Java-index,Java Essentials,Java Programming...