floatToStr

string
floatToStr
pure nothrow
(
T
)
(
in T val
,
int width = 0
,
int after_point = 6
,
bool remove_trailing_zeros = true
,,
char fill_char = ' '
)
if (
isNumeric!T
)
in { assert (after_point >= 0); }

Examples

1 assertEq( floatToStr(0), ".0" );
2 assertEq( floatToStr( 3.1415 ), "3.1415" );
3 assertEq( floatToStr( -3.1415 ), "-3.1415" );
4 assertEq( floatToStr( -3.1415, 6, 2 ), " -3.14" );
5 assertEq( floatToStr( 3.1415, 6, 2 ), "  3.14" );
6 assertEq( floatToStr( 3.1415, 6, 2, true, PlusSig.PLUS ), " +3.14" );
7 assertEq( floatToStr( 128, 6, 2, true, PlusSig.PLUS ), "+128.0" );
8 assertEq( floatToStr( 1286, 6, 2, true, PlusSig.PLUS ), "+1286.0" );
9 assertEq( floatToStr( 1286, 6, 0 ), " 1286." );
10 assertEq( floatToStr( 3.1415, 12, 8, false ),  "  3.14150000" );
11 assertEq( floatToStr( -3.1415, 12, 8, false ), " -3.14150000" );
12 assertEq( floatToStr(float.nan), "nan" );
13 assertEq( floatToStr(-float.nan), "-nan" );
14 assertEq( floatToStr(float.infinity), "inf" );
15 assertEq( floatToStr(-float.infinity), "-inf" );
16 
17 assertEq( floatToStr( 3.1415, 0, 2, true, PlusSig.NONE ), "3.14" );
18 assertEq( floatToStr( 3.1415, 0, 3, true, PlusSig.SPACE ), " 3.141" );
19 assertEq( floatToStr( 3.1415, 0, 2, true, PlusSig.PLUS ),  "+3.14" );

Meta