Java BigDecimal remove decimal and trailing numbers

Zero Cool picture Zero Cool · Aug 22, 2009 · Viewed 59k times · Source

I'm new to Java and trying to take a BigDecimal (for example 99999999.99) and convert it to a string but without the decimal place and trailing numbers. Also, I don't want commas in the number and rounding is not needed.

I've tried:

Math.Truncate(number)

but BigDecimal is not supported.

Any ideas?

Thanks very much.

Answer

S.Lott picture S.Lott · Aug 22, 2009

Use this.

BigDecimal truncated= number.setScale(0,BigDecimal.ROUND_DOWN);