Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Rounding  RSS feed

 
Drew Lane
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I thought this would be an easy question, but I got it wrong:
What is the value of the following expression:
Math.round(Math.random() + 2.50001);
Answer: 3
Isn't it possible the value of Math.random() could be 0.99999 ?
If it was then the value of the expression would be 3.5 which would be rounded to 4, no?
Thanks,
Drew
 
Junilu Lacar
Sheriff
Posts: 11125
160
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Drew, if this is coming from the RHE mock exam, the answer given is wrong. You are right about round() and random(), so the correct answer to that question would be "impossible to say"
 
Drew Lane
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
THANK YOU!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!