Printing floating point numbers

Yui Hosaka hos at hos.ac
Thu Oct 24 20:48:02 UTC 2019


The following code prints weird results on my machine.

----
import std.stdio;
void main() {
   real a = 0.16;
   real b = 0.016;
   writefln("%.1f", a);
   writefln("%.2f", b);
}
----

Output:
---
0.2
0.01
----

I am using dmd on Windows. It doesn't happen when compiling with 
-m32.
----
$ dmd
DMD32 D Compiler v2.088.1-dirty
----

Do you have any idea for this issue?



More information about the Digitalmars-d-learn mailing list