Retain precision with double in Java

前端 未结 22 3087
情歌与酒
情歌与酒 2020-11-21 05:15
public class doublePrecision {
    public static void main(String[] args) {

        double total = 0;
        total += 5.6;
        total += 5.8;
        System.out         


        
22条回答
  •  再見小時候
    2020-11-21 05:48

    Use java.math.BigDecimal

    Doubles are binary fractions internally, so they sometimes cannot represent decimal fractions to the exact decimal.

提交回复
热议问题