Why doesn't this Java calculation return a floating point value? -


Just wanted to know

  float percent = 1 + (25/100); // percent value is 1.0 and not 1.25   

returns result 1 but not 1.25

thanks sqt

I think Java looks at it like this:

  (int) 1 + (int) 25 / (int) 100) = (Int) 1   

And then it is stored in a float. Try it with 25 instead of 25.0 .

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -