Converting a String that contains decimal to Long

后端 未结 5 1434
庸人自扰
庸人自扰 2020-12-11 15:00

I have following sample (link to ideone).

long lDurationMillis =  0;
lDurationMillis = Long.parseLong(\"30000.1\");
System.out.print(\"Play Duration:\" + lD         


        
5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-11 15:25

    You could use BigDecimal in this case:

    BigDecimal bd = new BigDecimal("30000.1");
    long l = bd.setScale(0, BigDecimal.ROUND_HALF_UP).longValue();
    System.out.println(l);
    

提交回复
热议问题