Terrible math problem, help please.

Hi, I am trying to do a rounding method, it seems to work but on some cases iot fails on this:for example:360/100=3 instead of 3.6!!!! Why?
[160 byte] By [MelGohana] at [2007-11-27 5:43:56]
# 1

int result=360/100;

System.out.println(result);// print 3 because result is an int

since cldc 1.1 you can do

float result=360F / 100F;

System.out.println(result); // print 3.6 because result is a float

suparenoa at 2007-7-12 15:24:01 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 2
CLDC 1.0 does not support floating point types and there are no floats and doubles or the wrappers Float and Double.Keep in mind though, that the CLDC 1.1 Float and Double are different from their J2SE counterparts.
nogoodatcodinga at 2007-7-12 15:24:01 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 3
well I didnt used int result=360/100 butdouble result=360/100 and was getting 3I solved this on this way:double result=(double)360/100.Thanks a lot.
MelGohana at 2007-7-12 15:24:01 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 4

> well I didnt used int result=360/100 but

>

> double result=360/100 and was getting 3

yes, you are using int because '360/100' are int primitive values

System.out.println(360/100); // output 3 because 360 and 100 are int primitive

System.out.println(360D/100); // output 3.6 because one of the numbers is a double

System.out.println(360/100D); // // same as above !

> I solved this on this way:

>

> double result=(double)360/100.

your cast is not necessary. see the code above!

> Thanks a lot.

you're welcome

and it wasn't so terrible :-)

suparenoa at 2007-7-12 15:24:01 > top of Java-index,Java Mobility Forums,Java ME Technologies...