Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

writefln with floating-point numbers

Part of StandardLibraryCategory

Description

Demonstrates the use of writefln to display floating point numbers.

Example

import std.stdio;

void main()
{
    float f = 1.175494351e-38;
    double d = 1.175494351e-38;


    writefln("%%s: %s", f);
    writefln("%%g: %g", f);
    writefln("%%G: %G", f);

    writefln("%%s: %s", d);
    writefln("%%g: %g", d);
    writefln("%%G: %G", d);
}

Output

%s: 1.17549e-38
%g: 1.17549e-38
%G: 1.17549E-38
%s: 1.17549e-38
%g: 1.17549e-38
%G: 1.17549E-38

Compile Tips

Sample batch file:

@echo off
dmd float.d
float.exe
pause

Source

Inspired by digitalmars.D.bugs/6720.