toString

Convert a floating point number to a base-10 string at compile time. This function is very crude and will not work in many cases!

string
toString
pure nothrow
(
Float
)
(
in Float value
,
in uint precision
)
if (
isFloatingPoint!Float
)

Examples

1 enum x = 42.0;
2 enum y = -13.37f;
3 enum z = 0.9;
4 
5 static assert(float.nan.toString(0) == "nan");
6 static assert(double.infinity.toString(0) == "inf");
7 static assert((-double.infinity).toString(0) == "-inf");
8 static assert(x.toString(0) == "42");
9 static assert(x.toString(1) == "42.0");
10 static assert(y.toString(2) == "-13.37");
11 static assert(y.toString(1) == "-13.4");
12 static assert(y.toString(0) == "-13");
13 static assert(z.toString(1) == "0.9");
14 static assert(z.toString(0) == "1");

Meta