java - Show float number on a button -


i'm writing application android, , have difficulties writing float value on button text. tried this:

float percentage1 = (level1/16)*100; string s = float.tostring(percentage1); percent.settext(s+"%"); 

and this:

float percentage1 = (level1/16)*100f; percent.settext(float.tostring(percentage1)); 

it's show me 0.0% on button. if has on idea how that, please respond!

(level1/16) computed in integer arithmetic; i.e. remainder discarded.

to remedy, use (level1/16.0)*100;. using 16.0 causes expression evaluated in floating point.


Comments

Popular posts from this blog

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -