Java, rounding a double to two decimal places -


i'm trying round double nearest 2 decimal places however, rounding nearest full number.

for example, 19634.0 instead of 19634.95.

this current code use rounding

double area = math.round(math.pi*radius()*radius()*100)/100; 

i can't see going wrong.

many help.

well, math.round(math.pi*radius()*radius()*100) long. 100 int.

so math.round(math.pi*radius()*radius()*100) / 100 become long (19634).

change math.round(math.pi*radius()*radius()*100) / 100.0. 100.0 double, , result double (19634.95).


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -