becks becks - 1 year ago 215
Java Question

How to convert BigDecimal to hex string?

I have a number of type BigDecimal and I want to convert it to hexadecimal value.

example value = 18446744073709551616

is there a way to do this instead of doing it manually ?


Answer Source

Judging by your example you should rather use BigInteger then BigDecimal. Try maybe this way

new BigInteger("18446744073709551616").toString(16)

or if you cant change type of your object convert it to BigInteger before

new BigDecimal("18446744073709551616").toBigInteger().toString(16);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download