This example
fNum := 100.22
sTest2 := Format( "{:03.15f}", fNum )
returns sTest = 100.21999999
Format not enough precise
Re: Format not enough precise
Code: Select all
fNum := 100.22
sTest2 := Format( "{:03.15f}", fNum )
MsgBox % sTest2 ; 100.220000000000000
returns sTest = 100.21999999
when the var name should be sTest2
Above example works fine for me.
Re: Format not enough precise
Hallo.
My last example line is not a program line, but a descriptive text, where I reported sTest instead sTest2, sorry.
The program lines are only the first 2 lines.
I controlled the value in the variable list of the developing environment.
I test it many time.
It seem me the problem is no constant: many times before it seem works well, but I found the same problem with the negative value -100.22.
It seem me that is no a constant problem.
My last example line is not a program line, but a descriptive text, where I reported sTest instead sTest2, sorry.
The program lines are only the first 2 lines.
I controlled the value in the variable list of the developing environment.
I test it many time.
It seem me the problem is no constant: many times before it seem works well, but I found the same problem with the negative value -100.22.
It seem me that is no a constant problem.
Re: Format not enough precise
I do not believe this is a bug.
From the Docs:
Hope this helps!
From the Docs:
Also maybe worth mentioning, I get different results from different ahk versions.https://lexikos.github.io/v2/docs/Concepts.htm#pure-numbers
Note: There are some decimal fractions which the binary floating-point format cannot precisely represent, so a number is rounded to the closest representable number. This may lead to unexpected results. For example:One strategy for dealing with this is to avoid direct comparison, instead comparing the difference. For example:Code: Select all
MsgBox 0.1 + 0 ; 0.10000000000000001 MsgBox 0.1 + 0.2 ; 0.30000000000000004 MsgBox 0.3 + 0 ; 0.29999999999999999 MsgBox 0.1 + 0.2 = 0.3 ; 0 (not equal)
Code: Select all
MsgBox Abs((0.1 + 0.2) - (0.3)) < 0.0000000000000001
Hope this helps!
Re: Format not enough precise
Yes, thank you.
I solved the problem, but I think the problem must be solved into the language.
I solved the problem, but I think the problem must be solved into the language.
Re: Format not enough precise
There's nothing to "solve into the language" unless you want to wish for decimal-based floating-point numbers, instead of the binary format understood by your CPU and used by most programming languages by default.