intToStr

string
intToStr
pure nothrow
(
T
)
(
in T val
,
int width = 0
,,
int base = 10
,
char fill_char = ' '
)
if (
isIntegral!T
)
in { assert (val != T.min); assert (base > 0, "base must be > 0"); assert (base <= 16, "base must be <= 16"); }

Examples

1 assertEq( intToStr(0), "0" );
2 assertEq( intToStr(123), "123" );
3 assertEq( intToStr(-16), "-16" );
4 assertEq( intToStr(-16, 5), "  -16" );
5 
6 assertEq( intToStr(16, 5, PlusSig.NONE),  "   16" );
7 assertEq( intToStr(16, 5, PlusSig.SPACE), "   16" );
8 assertEq( intToStr(16, 5, PlusSig.PLUS),  "  +16" );
9 
10 assertEq( intToStr(16, 0, PlusSig.NONE),  "16" );
11 assertEq( intToStr(16, 0, PlusSig.SPACE), " 16" );
12 assertEq( intToStr(16, 0, PlusSig.PLUS),  "+16" );
13 
14 assertEq( intToStr(1234567, 5), "1234567" );
15 assertEq( intToStr(1234567, 5, PlusSig.PLUS), "+1234567" );
16 assertEq( intToStr(1234567, -5, PlusSig.PLUS), "+1234567" );
17 assertEq( intToStr(1234567, -5, PlusSig.SPACE), " 1234567" );
18 
19 assertEq( intToStr(16, 5, PlusSig.NONE, 10, 'x'), "xxx16" );
20 assertEq( intToStr(0, 10, PlusSig.NONE, 10, '0'), "0000000000" );
21 
22 assertEq( intToStr(3, 4, PlusSig.NONE, 2, '0'), "0011" );
23 assertEq( intToStr(3, 4, PlusSig.NONE, 8, '0'), "0003" );
24 assertEq( intToStr(9, 4, PlusSig.NONE, 8, '0'), "0011" );
25 
26 assertEq( intToStr(255, 3, PlusSig.NONE, 16 ), " FF" );
27 assertEq( intToStr(256, 3, PlusSig.NONE, 16 ), "100" );

Meta