Float - something wrong - AHK v2-a116 Topic is solved

Get help for the alpha version of AutoHotkey v2 here. Please state the v2 version you are working with in the title when making a new topic.
User avatar
TheArkive
Posts: 435
Joined: 05 Aug 2016, 08:06
GitHub: TheArkive

Float - something wrong - AHK v2-a116

14 Jul 2020, 15:37

This script for AHK v2:

msgbox 1.0009

Shows this value in the msgbox:

1.0008999999999999

EDIT: Tried this in AHK v2-a112 and a108 ... same thing.

I tried this in AHK v1.1.33:

msgbox % 1.0009

And the expected 1.0009 is displayed.
swagfag
Posts: 4126
Joined: 11 Jan 2017, 17:59

Re: Float - something wrong - AHK v2-a116  Topic is solved

14 Jul 2020, 15:49

https://lexikos.github.io/v2/docs/Concepts.htm#numbers wrote:Floating-point numbers are formatted with full precision (but discarding redundant trailing zeroes), which may in some cases reveal their inaccuracy.
lexikos
Posts: 7144
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Float - something wrong - AHK v2-a116

16 Jul 2020, 21:34

msgbox % 1.0009
The equivalent script for v2 is

Code: Select all

msgbox "1.0009"
because in v1 a floating-point literal is always just a string, but
All literal numbers are converted to pure binary numbers at load time and their string representation is discarded. For example, MsgBox 0x1 is equivalent to MsgBox 1, while MsgBox 1.0000 is equivalent to MsgBox 1.0 (because the float formatting has changed). Storing a number in a variable or returning it from a UDF retains its pure numeric status.
Source: v2-changes
User avatar
TheArkive
Posts: 435
Joined: 05 Aug 2016, 08:06
GitHub: TheArkive

Re: Float - something wrong - AHK v2-a116

17 Jul 2020, 00:59

Thanks @lexikos, looks like i gotta slow down and read more.

Return to “AutoHotkey v2 Help”

Who is online

Users browsing this forum: No registered users and 2 guests