ocean.text.convert.Float

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 = ocean.text.convert.Float;

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

Members

Functions

format
T[] format(T[] dst, NumType x, int decimals, int e, bool pad)

Convert a floating-point number to a string.

format
const(T)[] format(T[] output, V v, T[] fmt)

Format a floating-point value according to a format string

main
void main()
parse
NumType parse(T[] src, uint* ate)

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.

toFloat
NumType toFloat(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.

toString
char[] toString(NumType d, uint decimals, int e)

Template wrapper to make life simpler. Returns a text version of the provided value.

truncate
T[] truncate(T[] s)

Truncate trailing '0' and '.' from a string, such that 200.000 becomes 200, and 20.10 becomes 20.1

Meta

License

Tango Dual License: 3-Clause BSD License / Academic Free License v3.0. See LICENSE_TANGO.txt for details.

Version

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