Take a look at BigDecimal
Immutable, arbitrary-precision signed decimal numbers
And to answer your question - yes, you can crate data types, but they can't be primitive types (like int
, double
, etc). They have to be classes, just like the case with BigDecimal
(and BigInteger
)
And a further advice for using the Big*
classes - as written, they are immutable. This means that calling add(..)
doesn't change the object - it returns a new object that reflects the change. I.e.
BigDecimal dec = BigDecimal.ZERO;
dec.add(new BigDecimal(5)); // nothing happens
dec = dec.add(new BigDecimal(5)); // this works