I am using the following DecimalFormat
pattern:
// Use ThreadLocal to ensure thread safety.
private static final ThreadLocal <NumberFormat> numberFormat =
new ThreadLocal <NumberFormat>() {
@Override protected NumberFormat initialValue() {
return new DecimalFormat("#,##0.00");
}
};
This performs the following conversions:
1 -> 1.00
1.1 -> 1.10
1.12 -> 1.12
I now have an additional requirement.
1.123 -> 1.123
1.1234 -> 1.123
That means that when
Can I specify this behavior with the DecimalFormat
class?
DecimalFormat("#,##0.00#")
Have you tried to change the RoundingMode of your DecimalFormat
instance?
Calling setRoundingMode(RoundingMode.FLOOR)
should do the trick
See also setRoundingMode(java.math.RoundingMode)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With