I have Strings (from DB), which may contain numeric values. If it contains numeric values, I'd like to remove trailing zeros such as:
10.0000
-
10.234000
str.replaceAll("\\.0*$", "")
, works on the first one, but not the second one.
A lot of the answers point to use BigDecimal
, but the String
I get may not be numeric. So I think a better solution probably is through the Regex.