1 auto c = dual(1.2, 3.4); 2 3 // Vanilla toString formatting: 4 assert(c.toString() == "1.2+3.4ε"); 5 6 // Formatting with std.string.format specs: the precision and width 7 // specifiers apply to both the real and imaginary parts of the 8 // complex number. 9 import std.format : format; 10 assert(format("%.2f", c) == "1.20+3.40ε"); 11 assert(format("%4.1f", c) == " 1.2+ 3.4ε");
Converts the dual 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.