About auto rounding result in java from double to integer? -


the output of below code in java 3.0.

why isn't 3.3333333...?

double = 10 / 3; system.out.println(a); 

because int / int returns int (regardless of assign afterwards).

so 10 / 3 returns 3 (integer division rounds down).

this converted double.

to fix this, make 1 of values double (so it's double / int, returns double):

double = 10.0 / 3; 

or

double = (double)10 / 3; 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -