License:
BSD style: see license.txt

Version:
Initial release: Nov 2005

author:
Kris

A set of functions for converting between string and floating- point values.

Applying the D "import alias" mechanism to this module is highly recommended, in order to limit namespace pollution:
        import Float = tango.text.convert.Float;

        auto f = Float.parse ("3.14159");


  • NumType toFloat (T)(T[] src);
  • Convert a formatted string of digits to a floating-point number. Throws an exception where the input text is not parsable in its entirety.

  • char[] toString (real d, uint decimals = cast(uint)2, int e = 10);
  • Template wrapper to make life simpler. Returns a text version of the provided value.

    See format() for details

  • wchar[] toString16 (real d, uint decimals = cast(uint)2, int e = 10);
  • Template wrapper to make life simpler. Returns a text version of the provided value.

    See format() for details

  • dchar[] toString32 (real d, uint decimals = cast(uint)2, int e = 10);
  • Template wrapper to make life simpler. Returns a text version of the provided value.

    See format() for details

  • T[] format (T,D = double,U = uint)(T[] dst, D x, U decimals = Dec, int e = Exp);
  • 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

  • NumType parse (T)(T[] src, uint* ate = null);
  • Convert a formatted string of digits to a floating-point number. Good for general use, but use David Gay's dtoa package if serious rounding adjustments should be applied.

  • T[] truncate (T)(T[] s);
  • Truncate trailing '0' and '.' from a string, such that 200.000 becomes 200, and 20.10 becomes 20.1

    Returns a potentially shorter slice of what you give it.

    Copyright (c) 2004 Kris Bell. All rights reserved :: page rendered by CandyDoc