Full precision double to string conversion

Ecstatic Coder ecstatic.coder at gmail.com
Sat Nov 3 12:27:19 UTC 2018


import std.conv;
import std.stdio;
void main()
{
     double value = -12.000123456;
     writeln( value.sizeof );
     writeln( value );
     writeln( value.to!string() );
     writeln( value.to!dstring() );
}

/*
8
-12.0001
-12.0001
-12.0001
*/

In Dart, value.toString() returns "-12.000123456".

In C#, value.ToString() returns "-12.000123456".

In D, value.to!string() returns "-12.0001" :(

How can I convert a double value -12.000123456 to its string 
value "-12.000123456", i.e. without loosing double-precision 
digits ?




More information about the Digitalmars-d-learn mailing list