Transform to BigDecimal object
The meaning of "precision" and "scale" defined in BSONDecimal are
different from that defined in BigDecimal.
In BSONDecimal, "precision" represents the total number of digits
of decimal, and "scale" represents the max count of decimal digits
in the fractional part. For example, when we define a BSONDecimal
object which precision is 10 and scale is 6, that means this
BSONDecimal object can only represent a value which count of digits
in integer part is not more than 4(10-6) and count of digits in
fractional part is not more that 6. So, when we specify
"12345.6789" for this BSONDecimal object, if we insert this object
into database, we get an error about invalid argument. When we
specify "1234.1234507" for this BSONDecimal object, if we insert
this object into database, we finally get "1234.123451". We can get
only 6 digits after decimal point, and the last digit is rounding
to 1. when we specify "1.23E10" for this BSONDecimal object, we have
11 digits in the integer part, so when we insert this BSONDecimal
object into database, we get an error, too.
In BigDecimal, the value of the number represented by the
BigDecimal is (unscaledValue * 10^-scale). "precision" represents
the count of digits in unscaleValue, and "scale" is the value of
scale. For example, value "1234.567890" is represented by
BigDecimal like "1234567890 * 10^-6". So, unscaledValue is
"1234567890", precision is 10, and scale is 6. Value "1.2345E9" is
represented by BigDecimal like "12345 * 10^5". So, unscaledValue is
"12345", precision is 5, and scale is -5.
As above, we can see the difference between BSONDecimal and
BigDecimal. Actually, when we transform BSONDecimal to BigDecimal,
it's as below:
new BigDecimal(this.getValue()) // "this" means current BSONDecimal object