FormatSpec struct

Paul D. Anderson paul.d.removethis.anderson at comcast.andthis.net
Thu Apr 12 22:50:31 PDT 2012


I'm trying to add formatted output to my decimal arithmetic 
module. Decimals should format like floating point, using 'E', 
'F' and 'G', etc.

I would expect a format string like "%9.6e" to parse as width = 
9, precision = 6, using exponential notation.

In std.format there is a FormatSpec struct that looks as if it 
will do the parsing for me. As far as I can tell the usage is:

      auto spec = std.format.FormatSpec!char("9.6e");
      writeln("fmtspec = ", fmtspec);

But it doesn't do what I think it should do.

The output of the method is:

fmtspec = address = 1637116
width = 0
precision = 2147483646
spec = s
indexStart = 0
indexEnd = 0
flDash = false
flZero = false
flSpace = false
flPlus = false
flHash = false
nested =
trailing = 9.6e

The width field should be 9, the precision field should be 6, and 
the spec field should be 'e'. Instead it seems to disregard the 
input string and return a default FormatSpec, with only the 
'trailing' field populated, containing the input.

What am I missing here? I've tried variations -- "%9.6e", "s", 
"%s", etc, but the input is always relegated to the trailing 
field.

Paul




More information about the Digitalmars-d-learn mailing list