Home Ask Login Register

Developers Planet

Your answer is one click away!

Magesh Srinivasulu February 2016

precision error in output

double x = 9/2
//x == 4.0?

The output should be 4.5, but is 4.0 What would be the mistake I made?


user3659052 February 2016

9/2 <- without decimal you are specify this as a int

9.0 / 2.0 <- this is now double and you should able to get 4.5

Post Status

Asked in February 2016
Viewed 3,936 times
Voted 13
Answered 1 times


Leave an answer

Quote of the day: live life