Dividing long by long returns 0

java

Solution

You are probably dividing a long with a long, which refers to (long/long = long) operation, giving a long result (in your case 0).

You can achieve the same thing by casting either operand of the division to a float type.

Long Percentageused = (long)((float)totaloccupied/totaldrive*100);

Problem

I am trying to calculate % of used diskspace in Windows and totaldrive denotes total diskspace of c drive in Long and 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 someone help as I am not getting the desired value

Original source

Related problems