Android number format is wrong somehow, instead of 3.5 I get 3.499999999, why?

前端 未结 2 767
一向
一向 2021-01-23 00:04

I store some data in a database and I read those data with a cursor. All the data are 56.45 , 3.04, 0.03 type, so two numbers after the decimal point. Now I would like to sum th

2条回答
  •  失恋的感觉
    2021-01-23 00:15

    Other approach, you can define your sum variable as double and then you can set NumberFormat for your sum variable.

    Example:

    double sum = 21.2015;
    NumberFormat formatter = new DecimalFormat("#.##");
    formatter.format(sum);
    

提交回复
热议问题