Retain precision with double in Java

前端 未结 22 3075
情歌与酒
情歌与酒 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:54

    Pretty sure you could've made that into a three line example. :)

    If you want exact precision, use BigDecimal. Otherwise, you can use ints multiplied by 10 ^ whatever precision you want.

提交回复
热议问题