Weird floating point rounding - Bug or how to control it correctly
Basile B.
b2.temp at gmx.com
Thu Sep 14 05:06:20 UTC 2023
On Thursday, 14 September 2023 at 03:23:48 UTC, An Pham wrote:
> 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
Classic question. The float literal `6394763.345f` is not
representable as IEEE-754 floating point number.
Try https://www.h-schmidt.net/FloatConverter/IEEE754.html for a
short introduction to the issue.
More information about the Digitalmars-d-learn
mailing list