# 7 examples of 'python convert decimal to int' in Python

Every line of 'python convert decimal to int' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

## All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
``372def test__DECIMAL_to_python(self):373    """Convert a MySQL DECIMAL to a Python decimal.Decimal type"""374    data = b'3.14'375    exp = Decimal('3.14')376    res = self.cnv._DECIMAL_to_python(data)377378    self.assertEqual(exp, res)379380    self.assertEqual(self.cnv._DECIMAL_to_python,381                     self.cnv._NEWDECIMAL_to_python)``
``78def pythonvalue(self, value):79    return _Decimal(value)``
``16def format_decimal(value):17    return Decimal(value.quantize(Decimal('.01'), rounding=ROUND_HALF_UP))``
``60def test_decimal_int(self):61    a, b = mathfilters.handle_float_decimal_combinations(Decimal('2.0'), 1, '+')62    self.assertTrue(isinstance(a, Decimal), 'Type is {0}'.format(type(a)))63    self.assertTrue(isinstance(b, int), 'Type is {0}'.format(type(b)))``
``16def create_decimal(value, default=0):17    """Create a decimal from the passed value. This is a decimal that18       has 6 decimal places and is clamped between19       -1 quadrillion < value < 1 quadrillion20    """21    from decimal import Decimal as _Decimal2223    if value is None:24        return _Decimal(0, get_decimal_context())2526    try:27        d = _Decimal("%.6f" % value, get_decimal_context())28    except:29        value = _Decimal(value, get_decimal_context())30        d = _Decimal("%.6f" % value, get_decimal_context())3132    if d <= -1000000000000:33        from Acquire.Accounting import AccountError34        raise AccountError(35                "You cannot create a balance with a value less than "36                "-1 quadrillion! (%s)" % (value))3738    elif d >= 1000000000000000:39        from Acquire.Accounting import AccountError40        raise AccountError(41                "You cannot create a balance with a value greater than "42                "1 quadrillion! (%s)" % (value))4344    return d``
``10def convert_to_decimal(number, frac=False):11    bad_type = not isinstance(number, (int, long, str, unicode, Decimal, Fraction))12    if bad_type:13        message = "{}, of type {} is not suitable as a Decimal"14        logger.warning(message.format(number, type(number)))15    return Fraction(number) if frac else Decimal(number)``
``143def split_decimal(value):144    import decimal145    decimal.getcontext().prec = 2146    d = decimal.Decimal(value)147    i = int(d)148    return (i, d - i)``