Java Arithmetic division
问题 public class test { public static void main(String[] args) { int total = 2; int rn = 1; double rnp = (rn / total) * 100; System.out.println(rnp); } } Why it prints 0.0 instead of 50.0? https://www.google.com/search?q=100*(1%2F2)&aq=f&oq=100*(1%2F2) 回答1: The division occurs in integer space with no notion of fractions, you need something like double rnp = (rn / (double) total) * 100 回答2: You are invoking integer division here (rn / total) Integer division rounds towards zero. Try this instead: