Decimal.this

Constructs Decimal from the floating point number using the Ryu algorithm.

The number is the shortest decimal representation that being converted back would result the same floating-point number.

  1. this(const(C)[] str, int exponentShift)
  2. this(T x)
    struct Decimal(size_t maxSize64)
    this
    (
    T
    )
    (
    const T x
    )
    if (
    isFloatingPoint!T &&
    maxSize64 >= 1 + (T.mant_dig >= 64)
    )
    if (
    maxSize64 &&
    maxSize64 <= ushort.max
    )

Examples

// float and double can be used to construct Decimal of any length
auto decimal64 = Decimal!1(-1.235e-7);
assert(decimal64.exponent == -10);
assert(decimal64.coefficient == -1235);

// real number may need Decimal at least length of 2
auto decimal128 = Decimal!2(-1.235e-7L);
assert(decimal128.exponent == -10);
assert(decimal128.coefficient == -1235);

decimal128 = Decimal!2(1234e3f);
assert(decimal128.exponent == 3);
assert(decimal128.coefficient == 1234);

Meta