Home > OS >  how do i restric a float value to only one placess after decimal in kotlin android
how do i restric a float value to only one placess after decimal in kotlin android

Time:04-27

I have a number with some number decimal places, How can i round this float number with one number decimal places

for example 1.366565646 convert to 1.3

CodePudding user response:

In your case I think you need to trim the number not round it, You can use this:

 double d = 1.366565646;
 DecimalFormat df = new DecimalFormat("#.#");
 double p = Double.parseDouble(df.format(d));
  • Related