adding n number of zeros after decimal

前端 未结 3 376
猫巷女王i
猫巷女王i 2020-12-20 02:06

I need to give accuracy of a number entered by user till few digit. like if user enter some random value and gives that he wants accuracy till three digit then I need to rou

3条回答
  •  既然无缘
    2020-12-20 02:33

    You can indeed use NumberFormat to do this

    double amount = 15;
    NumberFormat formatter = new DecimalFormat("#0.000");
    System.out.println("The Decimal Value is:"+formatter.format(amount));
    

提交回复
热议问题