How to remove decimal values from a value of type 'double' in Java

后端 未结 19 1930
孤独总比滥情好
孤独总比滥情好 2020-12-08 09:26

I am invoking a method called \"calculateStampDuty\", which will return the amount of stamp duty to be paid on a property. The percentage calculation works fine, and returns

19条回答
  •  不思量自难忘°
    2020-12-08 09:44

    Double i = Double.parseDouble("String with double value");
    
    Log.i(tag, "display double " + i);
    
    try {
        NumberFormat nf = NumberFormat.getInstance();
        nf.setMaximumFractionDigits(0); // set as you need
        String myStringmax = nf.format(i);
    
        String result = myStringmax.replaceAll("[-+.^:,]", "");
    
        Double i = Double.parseDouble(result);
    
        int max = Integer.parseInt(result);
    } catch (Exception e) {
        System.out.println("ex=" + e);
    }
    

提交回复
热议问题