class BSON::Decimal128::Builder::FromString

def round_exact(exponent, significand)

def round_exact(exponent, significand)
  if exponent < Decimal128::MIN_EXPONENT
    if significand.to_i == 0
      round = Decimal128::MIN_EXPONENT - exponent
      exponent += round
    elsif trailing_zeros = TRAILING_ZEROS_REGEX.match(significand)
      round = [ (Decimal128::MIN_EXPONENT - exponent),
                trailing_zeros[1].size ].min
      significand = significand[0...-round]
      exponent += round
    end
  elsif significand.length > Decimal128::MAX_DIGITS_OF_PRECISION
    trailing_zeros = TRAILING_ZEROS_REGEX.match(significand)
    if trailing_zeros
      round = [ trailing_zeros[1].size,
                (significand.length - Decimal128::MAX_DIGITS_OF_PRECISION),
                (Decimal128::MAX_EXPONENT - exponent)].min
      significand = significand[0...-round]
      exponent += round
    end
  end
  [ exponent, significand ]
end