BSD style: see
license.txt
Initial release: Nov 2005
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");
|
- enum [private] ¶#
-
Constants
- 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(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[] 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.
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.
- NumType pow10(uint exp) [private] ¶#
-
Internal function to convert an exponent specifier to a floating
point value.