Complex.toString

Converts the complex number to a string representation.

The second form of this function is usually not called directly; instead, it is used via std.string.format, as shown in the examples below. Supported format characters are 'e', 'f', 'g', 'a', and 's'.

See the std.format and std.string.format documentation for more information.

  1. string toString()
  2. void toString(Writer w, FormatSpec!Char formatSpec)
    struct Complex(T)
    const
    void
    toString
    (
    Writer
    Char
    )
    (
    scope Writer w
    ,
    scope const ref FormatSpec!Char formatSpec
    )
    if (
    isOutputRange!(Writer, const(Char)[])
    )

Examples

auto c = complex(1.2, 3.4);

// Vanilla toString formatting:
assert(c.toString() == "1.2+3.4i");

// Formatting with std.string.format specs: the precision and width
// specifiers apply to both the real and imaginary parts of the
// complex number.
import std.format : format;
assert(format("%.2f", c)  == "1.20+3.40i");
assert(format("%4.1f", c) == " 1.2+ 3.4i");

Meta