No replies
210 Posts

Pinned topic MathFloor

‏2007-05-10T00:04:56Z |
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
I though of error conditions as error conditions when the user inputs something that can't be parsed as an int?

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

how do i write an applet?