Using Math.round to round to one decimal place?

前端 未结 9 1258
别跟我提以往
别跟我提以往 2020-12-05 09:39

I have these two variables

double num = 540.512
double sum = 1978.8

Then I did this expression

double total = Math.round((         


        
9条回答
  •  一向
    一向 (楼主)
    2020-12-05 10:05

    Double toBeTruncated = new Double("2.25");
    
    Double truncatedDouble = new BigDecimal(toBeTruncated).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
    

    it will return 2.3

提交回复
热议问题