Reputation: 15
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
Upvotes: 0
Views: 957
Reputation: 354
Following code will work for coversion in Kotlin :
val floatValue = 12.642054
val parsedValue = ((floatValue * 10).toInt()).toFloat() / 10
Upvotes: 1
Reputation: 289
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));
Upvotes: 4