For example I have the variable 3.545555555, which I would want to truncate to just 3.54.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
You can use NumberFormat Class object to accomplish the task.
Formating as a string and converting back to double i think will give you the result you want.
The double value will not be round(), floor() or ceil().
A quick fix for it could be:
You can use the sValue for display purposes or the newValue for calculation.
Maybe following :
A quick check is to use the Math.floor method. I created a method to check a double for two or less decimal places below:
I have a slightly modified version of Mani's.
Output:
3.545555555 to get 3.54. Try Following for this:
This will give= 3.54!