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

Number Division NaN value returned??  RSS feed

 
russakis russakis
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi! i'm trying to divide a double to an integer.

The values of each number are correct (meaning no infinite or null values).
I try to do something like double result = a/b ; . Whereas a is double and b is integer.

But i get an NaN as result..
Can you help me out?
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are the values of the variables? Can you post a small and complete example (that we can compile and run) to reproduce the problem?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If a and b are not infinite or NaN, then you've probably got 0 divided by 0, which gives NaN. You probably need to either modify your code so this never happens, or treat 0/0 as a special case. It all depends on what the purpose of your program is.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!