Hello, is there any round off function available in j2me. let's say if i want to get ronded value of float f = 3.45 and want to store it in integer data type then please tell me the method.
Hello, is there any round off function available in j2me. let's say if i want to get ronded value of float f = 3.45 and want to store it in integer data type then please tell me the method.
Look at Math.round(). (I'm assuming that ME implements all of Math.) You have to first multiply the number, in your example, by 100.0, then do the round() call to get an int that is 100 times the float/double value.
If Math.round() is for some reason unavailable you'd multiply by 100.0, add 0.5, and then take the int of that.
A lot harder if you want to round it to a value with N decimal digits of precision, but with the decimal point allowed to float.
http://java.sun.com/j2se/1.4.2/docs/...nd%28double%29
Here's round():
(Of course, this just leaves you asking what floor() is, I suppose.)Code:public static long round(double a) { return (long)floor(a + 0.5d); }
Thanks danhicksbyron, i used floor and got the desired result.