Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
double (float) type variable
#1
Code:
Copy      Help
double d=9/2
if d>4.4
    out "yes"
else
    out "no"
the output is "no". Can someone explain that - d should be 4.5 and if should return "yes"
#2
double d=9/2

at first calculates 9/2. Both are integers, therefore result is integer (4). Then it is assigned to d.
to calculate as doubles, use 9/2.0 or 9.0/2 or 9.0/2.0 or 1.0*9/2 etc.


Forum Jump:


Users browsing this thread: 1 Guest(s)