# Thread: Rounding double value

1. ## Rounding double value

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.

2. ## Re: Rounding double value

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

3. ## Re: Rounding double value

Here's round():
Code:
```    public static long round(double a) {
return (long)floor(a + 0.5d);
}```
(Of course, this just leaves you asking what floor() is, I suppose.)

4. ## Re: Rounding double value

Thanks danhicksbyron, i used floor and got the desired result.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•