tango.text.convert.Float

License:

BSD style: see license.txt

Version:

Nov 2005: Initial release Jan 2010: added internal ecvt()

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:
1
2
3
import Float = tango.text.convert.Float;

auto f = Float.parse ("3.14159");
NumType toFloat(T)(const(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(NumType d, uint decimals = Dec, int e = Exp)
Template wrapper to make life simpler. Returns a text version of the provided value.
See format() for details
wchar[] toString16(NumType d, uint decimals = Dec, int e = Exp)
Template wrapper to make life simpler. Returns a text version of the provided value.
See format() for details
dchar[] toString32(NumType d, uint decimals = Dec, int e = Exp)
Template wrapper to make life simpler. Returns a text version of the provided value.
See format() for details
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.
T[] format(T)(T[] dst, NumType x, int decimals = Dec, int e = Exp, bool pad = Pad)
Convert a floating-point number to a string.
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. Parameter pad will append trailing '0' decimals when set ~ otherwise trailing '0's will be elided
NumType parse(T)(const(T[]) src, size_t* 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.