长期划分长回报0 [英] Dividing long by long returns 0

查看:95
本文介绍了长期划分长回报0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试计算Windows中已用磁盘空间的百分比,而totaldrive表示Long中的C驱动器的总磁盘空间和Long中的freedrive dentoes可用空间。

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;

此处计算使用百分比

 Long Percentageused =(totaloccupied/totaldrive*100);
 System.out.println(Percentageused);

print语句返回0.有人可以提供帮助,因为我没有得到所需的值

The print statement returns 0. Can someone help as I am not getting the desired value

推荐答案

你可能将long换成long,指的是(long / long = long)操作,给出一个很长的结果(在你的case 0)。

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);

这篇关于长期划分长回报0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆