Remove the leading 0's till the decimal

前端 未结 3 1526

I want to remove the leading zeros in the decimal numbers.

So i want the output should be .324 not 0.324. I tried str.replaceFi

3条回答
  •  悲哀的现实
    2021-01-17 07:27

    do you want this for printing purposes? you wont be able to do any math using this, so i guess yes. then you could do:

    BigDecimal number =new BigDecimal(0.254); 
           System.out.println(number.toString().substring(number.toString().indexOf("0.")+1));
    

    output

    .254000000000000003552713678800500929355621337890625

提交回复
热议问题