A BigDecimal consists of an arbitrary precision integer unscaled value and a 32-bit integer scale. If zero or positive, the scale is the number of digits to the right of the decimal point. If negative, the unscaled value of the number is multiplied by ten to the power of the negation of the scale.
Since BigDecimal is immutable, these operations do not modify the existing objects. Rather, they return new objects.
See PostgreSQL datatypes - perhaps Numeric, which can act as an arbitrary precision type (this is a PostgreSQL extension).
...without any precision or scale creates a column in which numeric values of any precision and scale can be stored, up to the implementation limit on precision.
I am not entirely sure what "implementation limit on precision is", though. Have never tried really large numbers. If the limit is reached, then a fallback to text
is possible. But, I suspect there will be significant other issues before then ;-) If you wish to store less, then specify a precision and/or scale to numeric
.
Edit as sjr pointed out, the restriction is 1000 decimal digits of precision (from the same link):
The type numeric can store numbers with up to 1000 digits of precision [in currentl implementations] and perform calculations exactly. It is especially recommended for storing monetary amounts and other quantities where exactness is required...
If more precision is needed - despite having a much bigger problem at hand - then a numeric column will not be suitable (by itself). But this is really more of a very extreme "what if" and likely does not play a limiting role.
Just use the Java mappings for the common SQL data types. In this case you can use a NUMERIC or DECIMAL.
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