Friday, 15 June 2012

java - Math -not getting result when less than 1 -



java - Math -not getting result when less than 1 -

i have math problem. simple one, reason can't simple math action show within textview.

i want show user knowledge entered values calculation double. tried getting textview using double.tostring.. code is

double knoledgepercentage = ((100/(endingpoint - startingpoint))*knowncount); tv.settext(double.tostring(knoledgepercentage));

the thing tried doing math number, see variables ok. id did this:

double knoledgepercentage = ((100/400)*3); tv.settext(double.tostring(knoledgepercentage));

and still shows 0.0 in textview. just clear problem not using textview doing math.

you using integer partition in java, truncates decimal, because int divided int must still yield int. so, 100/400 0 in java, not 0.25. assigned double , promoted double, 0.0.

cast 1 of literals double or utilize double literals forcefulness floating-point math.

double knoledgepercentage = (((double) 100/400)*3);

or

double knoledgepercentage = ((100.0/400)*3);

java android math

No comments:

Post a Comment