struct Decimal
A struct representing a decimal fixed-point number.
By default, the number of digits after the decimal point is 18. The decimal point position is limited by the maximum value of the size_t data type. Decimal is based on std.bigint.BigInt and have no limitation for the number of significant digits.
this(BigInt number, size_t fixedPointPosition = defaultFixedPoint)
Constucts an object from a BigInt object.
Parameters
| number | BigInt |
| fixedPointPosition | Position of decimal point in new object. |
this(real number, size_t fixedPointPosition = defaultFixedPoint)
Constucts an object from a floating point number. (For good precision, give preference to forming a decimal number from a string.)
Parameters
| number | Floating point number of a built-in data type. |
| fixedPointPosition | Position of decimal point in new object. |
string toFullString() const
Converts to a human readable decimal string. All characters after the dot (with all zeros) will be shown according to the configured fixed point position.
void toString(scope void delegate(const(char)[]) sink, FormatSpec!char fmt) const
Convert the Decimal to string, passing it to the given sink.
Available format indicators: %D (or %f instead it) and %s.
For %D (or %f) there are available '+', '0' and width with precision
like for floating. For example, "%+08.5D".
Parameters
| sink | An OutputRange for accepting possibly piecewise segments of the formatted string. |
| fmt | A format string specifying the output format. |
Decimal opBinaryRight(string op, T)(T value) const
if (op.among("+", "*", "-", "/", "^^"))
Implements operators with built-in integers on the left-hand side
and Decimal on the right-hand side.
The precision of the decimal result is equal to the precision of the decimal argument.
Decimal opOpAssign(string op, T)(T value)
if (op.among("+", "-", "*", "/", "^^"))
Implements assignment operators of the form Decimal op= integer:
"+=", "-=", "*=", "/=", "^^=".
Position of the fixed point (precision) doesn't change.