# Difference between Math.round() and Math.rint()

Page 1 of 1

## 5 Replies - 17209 Views - Last Post: 15 March 2010 - 06:31 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=162149&amp;s=ff0cc686618595783c88d2670ce0b7fe&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 darek9576

• D.I.C Lover

Reputation: 202
• Posts: 1,710
• Joined: 13-March 10

# Difference between Math.round() and Math.rint()

Posted 15 March 2010 - 05:14 PM

Hey, just as the topic title indicates i want to know the difference between Math.rint() and Math.round()
as as far as i know they do the same thing.. Any feedback would be helpful. Thx in advance
Is This A Good Question/Topic? 1

## Replies To: Difference between Math.round() and Math.rint()

### #2 pdkharkar

• D.I.C Regular

Reputation: 65
• Posts: 345
• Joined: 19-January 09

## Re: Difference between Math.round() and Math.rint()

Posted 15 March 2010 - 05:48 PM

Math.rint(double) returns a double value closest to the argument that is passed to it and equal to the mathematical integer. Math.round(double) returns a long value closest to the value passed to it
This code demonstrates the thing
```class RoundRint
{
public static void main(String[] args)
{
double val = 424.122262;

System.out.println(Math.rint(val));
System.out.println(Math.round(val));
}
}

```

The output is

Quote

424.0
424

Hope this helps
Happy Coding

This post has been edited by pdkharkar: 15 March 2010 - 06:16 PM

### #3 pbl

• There is nothing you can't do with a JTable

Reputation: 8365
• Posts: 31,956
• Joined: 06-March 08

## Re: Difference between Math.round() and Math.rint()

Posted 15 March 2010 - 06:05 PM

You cannot always
double x = Math.round(val);

because if wont work if val is ouside int range like if val = 1.000E10 or 1.000E-10

### #4 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 11447
• Posts: 43,142
• Joined: 27-December 08

## Re: Difference between Math.round() and Math.rint()

Posted 15 March 2010 - 06:16 PM

pdkharkar, on 15 March 2010 - 08:48 PM, said:

Math.random(double) returns a long value closest to the value passed to it

Don't you mean Math.round()?

### #5 pdkharkar

• D.I.C Regular

Reputation: 65
• Posts: 345
• Joined: 19-January 09

## Re: Difference between Math.round() and Math.rint()

Posted 15 March 2010 - 06:18 PM

macosxnerd101, on 16 March 2010 - 05:46 AM, said:

pdkharkar, on 15 March 2010 - 08:48 PM, said:

Math.random(double) returns a long value closest to the value passed to it

Don't you mean Math.round()?

@macosxnerd101
Extremely sorry sir
and thanks for correcting
I could have totally confused darek9576
Thanks again

### #6 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 11447
• Posts: 43,142
• Joined: 27-December 08

## Re: Difference between Math.round() and Math.rint()

Posted 15 March 2010 - 06:31 PM

Not a problem. I think he knew what you meant. It was just a little typo.

Edit: It double posted for some reason.

This post has been edited by macosxnerd101: 15 March 2010 - 06:31 PM