Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Math.round() for negative numbers

 
Angela lewis
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone please explain how Math.round() works for negative numbers.
 
anandkumar gangoni
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well... Math.round method comes in 2 flavours where one form returns int on taking float as an argument and the other return long on taking double as argument.

whether the argument is negative or positive wat it does is........ it adds 0.5 to the argument and returns the floor value in int or long type depending on the argument provied.

shall be waiting to here from you.
till then this is Anand saying....
Cheers!!
 
anandkumar gangoni
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
an addition to wat i said

If NaN is the argument passed to Math.round, then the return value is zero.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're wondering how anandkumar gangoni could possibly know such a thing, I'll give you a hint to his wisdom. Take a look at the J2SE API documentation.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic