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