Converting a String that contains decimal to Long

后端 未结 5 1438
庸人自扰
庸人自扰 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:32

    You can do NumberFormat handling as below :

    long lDurationMillis =  0;
            try{
                NumberFormat nf = NumberFormat.getInstance();
                lDurationMillis = nf.parse("30000.1").longValue();
                System.out.print("Play Duration:" + lDurationMillis);
            }catch(ParseException e)
            {
                e.printStackTrace();
            }
    

    Output:

    Play Duration:30000
    

提交回复
热议问题