Retain precision with double in Java

前端 未结 22 3156
情歌与酒
情歌与酒 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 06:05

    Check out BigDecimal, it handles problems dealing with floating point arithmetic like that.

    The new call would look like this:

    term[number].coefficient.add(co);
    

    Use setScale() to set the number of decimal place precision to be used.

提交回复
热议问题