decimal
A real number data type with high precision.
Not a complete equivalent of floating-point types, as there are a fixed maximum number of digits before the decimal point (131072, or 2^17 digits) and after the decimal point (20 digits).
Examples:
123.456.7897e+33decimal('123456789.98765')
Since
0.9.1
Constructors
Functions
Round this decimal to the nearest whole number.
Examples:
(-0.4).round()returns0(0.4).round()returns0(1.49999999999999999999).round()returns1(1.5).round()returns2
Round this decimal to a specific number of decimal places.
decimal.round(0) is equivalent to decimal.round(), i.e. rounding will be to the nearest whole number. Positive arguments round to an increasing number of decimal places, e.g. 1 rounds to the neartest tenth, 2 to the nearest hundredth, 3 to the nearest thousandth. Negative arguments round in the opposite way, i.e. -1 rounds to the nearest ten, -2 to the nearest hundred, -3 to the nearest thousand.
Examples:
(123.456).round(0)returns123(123.456).round(-1)returns120(123.456).round(1)returns123.4(123.456).round(-2)returns100(123.456).round(2)returns123.45(123.456).round(-3)returns0(123.456).round(3)returns123.456
Convert this decimal to a big_integer, truncating the fractional part.
Numerically equivalent to decimal.floor(), but with a type conversion.
Convert this decimal to an integer, truncating the fractional part.
Numerically equivalent to decimal.floor(), but with a type conversion.
Convert this decimal to a base 10 text representation.
Convert this decimal to a base 10 text representation, optionally using scientific notation (also called standard form), e.g. 6.0221E+23.
The general output format when scientific notation is used is mEsn, where m represents a non-zero coefficient, E is the literal character, s represents the sign (either + or -), and n represents the exponent.
Note that the maximum number of decimal places for the coefficient is 20, and therefore any precision beyond this in the original decimal value is lost.