Vjy*_*Vjy 1 java integer-arithmetic
public class test {
public static void main(String[] args) {
int total = 2;
int rn = 1;
double rnp = (rn / total) * 100;
System.out.println(rnp);
}
}
Run Code Online (Sandbox Code Playgroud)
为什么它打印0.0而不是50.0?
https://www.google.com/search?q=100*(1%2F2)&aq=f&oq=100*(1%2F2)
除法发生在整数空间中,没有分数的概念,你需要类似的东西
double rnp = (rn / (double) total) * 100
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2072 次 |
| 最近记录: |