I need to trunk a float number with one decimal place. For eg: i have a float number called total=95.20004. my result should be 95.2. I have tried with the DecimalForma, but it is not working out. Kindly help me to resolve this issue.
You should be more specific as to what you want to do with your truncated number.
Do you want to put it in a String? Do you want to print it to the screen and keep the exact value in your variable? Do you want to truncate the result in your double variable?
Only printing to the screen: System.printf("%.1f", number);
Truncated number as a String: String.format("%.1f", number); and assign it to a String reference variable.
Truncate the result in your double variable: number = (int) (number * 10) / 10.0;