Human friendly precise output (default)
1 auto spec = NumericSpec.human; 2 auto buffer = stringBuf; 3 4 void check(double num, string value) 5 { 6 buffer.print(num, spec); 7 assert(buffer.data == value, value); 8 buffer.reset; 9 } 10 11 check(-0.0, "-0.0"); 12 check(0.0, "0.0"); 13 check(-0.01, "-0.01"); 14 check(0.0125, "0.0125"); 15 check(0.000003, "0.000003"); 16 check(-3e-7, "-3e-7"); 17 check(123456.0, "123456.0"); 18 check(123456.1, "123456.1"); 19 check(12.3456, "12.3456"); 20 check(-0.123456, "-0.123456"); 21 check(0.1234567, "0.1234567"); 22 check(0.01234567, "0.01234567"); 23 check(0.001234567, "0.001234567"); 24 check(1.234567e-4, "1.234567e-4"); 25 check(-1234567.0, "-1.234567e+6"); 26 check(123456.7890123, "123456.7890123"); 27 check(1234567.890123, "1.234567890123e+6"); 28 check(1234567890123.0, "1.234567890123e+12"); 29 check(0.30000000000000004, "0.30000000000000004"); 30 check(0.030000000000000002, "0.030000000000000002"); 31 check(0.0030000000000000005, "0.0030000000000000005"); 32 check(3.0000000000000003e-4, "3.0000000000000003e-4"); 33 check(+double.nan, "nan"); 34 check(-double.nan, "nan"); 35 check(+double.infinity, "+inf"); 36 check(-double.infinity, "-inf"); 37 38 spec.separatorChar = ','; 39 40 check(-0.0, "-0.0"); 41 check(0.0, "0.0"); 42 check(-0.01, "-0.01"); 43 check(0.0125, "0.0125"); 44 check(0.000003, "0.000003"); 45 check(-3e-7, "-3e-7"); 46 check(123456.0, "123,456.0"); 47 check(123456e5, "12,345,600,000.0"); 48 check(123456.1, "123,456.1"); 49 check(12.3456, "12.3456"); 50 check(-0.123456, "-0.123456"); 51 check(0.1234567, "0.1234567"); 52 check(0.01234567, "0.01234567"); 53 check(0.001234567, "0.001234567"); 54 check(1.234567e-4, "0.0001234567"); 55 check(-1234567.0, "-1,234,567.0"); 56 check(123456.7890123, "123,456.7890123"); 57 check(1234567.890123, "1,234,567.890123"); 58 check(123456789012.0, "123,456,789,012.0"); 59 check(1234567890123.0, "1.234567890123e+12"); 60 check(0.30000000000000004, "0.30000000000000004"); 61 check(0.030000000000000002, "0.030000000000000002"); 62 check(0.0030000000000000005, "0.0030000000000000005"); 63 check(3.0000000000000003e-4, "0.00030000000000000003"); 64 check(3.0000000000000005e-6, "0.0000030000000000000005"); 65 check(3.0000000000000004e-7, "3.0000000000000004e-7"); 66 check(+double.nan, "nan"); 67 check(-double.nan, "nan"); 68 check(+double.infinity, "+inf"); 69 check(-double.infinity, "-inf"); 70 71 spec.separatorChar = '_'; 72 spec.separatorCount = 2; 73 check(123456e5, "1_23_45_60_00_00.0"); 74 75 spec.plus = true; 76 check(0.0125, "+0.0125"); 77 check(-0.0125, "-0.0125");
Prints floating point numbers