Weird floating point rounding - Bug or how to control it correctly

An Pham home at home.com
Thu Sep 14 03:23:48 UTC 2023


import std.stdio;

     void main()
     {
         float f = 6394763.345f;
     	
         import std.format : sformat;

         char[80] vBuffer = void;
         writeln("6394763.345 = ", sformat(vBuffer[], "%.4f", f));
     	
     }

Output
6394763.345 = 6394763.5000


More information about the Digitalmars-d-learn mailing list