format

Convert a float to a string. This produces pretty good results for the most part, though one should use David Gay's dtoa package for best accuracy.

Note that the approach first normalizes a base10 mantissa, then pulls digits from the left side whilst emitting them (rightward) to the output.

The e parameter controls the number of exponent places emitted, and can thus control where the output switches to the scientific notation. For example, setting e=2 for 0.01 or 10.0 would result in normal output. Whereas setting e=1 would result in both those values being rendered in scientific notation instead. Setting e to 0 forces that notation on for everything.

TODO: this should be replaced, as it is not sufficiently accurate

  1. T[] format(T[] dst, NumType x, int decimals, int e, bool pad)
  2. T[] format(T[] dst, D x, U decimals, int e, bool pad)
    version(float_old)
    T[]
    format
    (
    T
    D = double
    U = uint
    )
    (
    T[] dst
    ,
    D x
    ,
    U decimals = Dec
    ,
    int e = Exp
    ,
    bool pad = Pad
    )
  3. T[] format(T[] dst, NumType x, uint decimals, int e, bool pad)

Meta