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.
372 def 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) 377 378 self.assertEqual(exp, res) 379 380 self.assertEqual(self.cnv._DECIMAL_to_python, 381 self.cnv._NEWDECIMAL_to_python)
78 def pythonvalue(self, value): 79 return _Decimal(value)
16 def format_decimal(value): 17 return Decimal(value.quantize(Decimal('.01'), rounding=ROUND_HALF_UP))
60 def 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)))
16 def create_decimal(value, default=0): 17 """Create a decimal from the passed value. This is a decimal that 18 has 6 decimal places and is clamped between 19 -1 quadrillion < value < 1 quadrillion 20 """ 21 from decimal import Decimal as _Decimal 22 23 if value is None: 24 return _Decimal(0, get_decimal_context()) 25 26 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()) 31 32 if d <= -1000000000000: 33 from Acquire.Accounting import AccountError 34 raise AccountError( 35 "You cannot create a balance with a value less than " 36 "-1 quadrillion! (%s)" % (value)) 37 38 elif d >= 1000000000000000: 39 from Acquire.Accounting import AccountError 40 raise AccountError( 41 "You cannot create a balance with a value greater than " 42 "1 quadrillion! (%s)" % (value)) 43 44 return d
10 def 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)
143 def split_decimal(value): 144 import decimal 145 decimal.getcontext().prec = 2 146 d = decimal.Decimal(value) 147 i = int(d) 148 return (i, d - i)