java - Dividing long by long returns 0 -


this question has answer here:

i trying calculate % of used diskspace in windows , totaldrive denotes total diskspace of c drive in long , freedrive dentoes free space in long.

 long totaloccupied = totaldrive - freedrive; 

here calculating % of usage

 long percentageused =(totaloccupied/totaldrive*100);  system.out.println(percentageused); 

the print statement returns 0. can not getting desired value

you dividing long long, refers (long/long = long) operation, giving long result (in case 0).

you can achieve same thing casting either operand of division float type.

long percentageused = (long)((float)totaloccupied/totaldrive*100); 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -