String to number

Discuss the future of the AutoHotkey language
arcticir
Posts: 508
Joined: 17 Nov 2013, 11:32

String to number

12 Aug 2018, 07:55

I need to convert the values ​​in the string to numeric values. I found this very difficult. Do you have any quick methods?

I found that converting them requires a complicated process:
e.g. ["6.9","232","-8.3"]
User avatar
nnnik
Posts: 3049
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: String to number

12 Aug 2018, 08:10

You can just calculate with them?
In AHK every string can be used like a number as long as it only consists of a single number (e.g. the numbers you presented.)
Recommends AHK Studio
Helgef
Posts: 3093
Joined: 17 Jul 2016, 01:02
Contact:

Re: String to number

12 Aug 2018, 08:17

There are two (suitable) functions available, integer and float.
arcticir
Posts: 508
Joined: 17 Nov 2013, 11:32

Re: String to number

12 Aug 2018, 08:24

Yes, but as some DLL parameters, need to convert.
arcticir
Posts: 508
Joined: 17 Nov 2013, 11:32

Re: String to number

12 Aug 2018, 08:27

Helgef wrote:There are two (suitable) functions available, integer and float.


Can you link the addresses of these two functions? I can't find.

Image
guest3456
Posts: 2353
Joined: 09 Oct 2013, 10:31

Re: String to number

12 Aug 2018, 08:30

arcticir wrote:
Helgef wrote:There are two (suitable) functions available, integer and float.


Can you link the addresses of these two functions? I can't find.


https://lexikos.github.io/v2/docs/commands/Integer.htm
https://lexikos.github.io/v2/docs/commands/Float.htm
https://lexikos.github.io/v2/docs/commands/String.htm
https://lexikos.github.io/v2/docs/commands/Type.htm

arcticir
Posts: 508
Joined: 17 Nov 2013, 11:32

Re: String to number

12 Aug 2018, 08:52

thank you very much. My "help document" is too old. :shock:
arcticir
Posts: 508
Joined: 17 Nov 2013, 11:32

Re: String to number

12 Aug 2018, 09:02

One problem is that its conversion is not accurate, it is very bad when converting JSON data:

Float("6.9") ;==>6.9000000000000004
Helgef
Posts: 3093
Joined: 17 Jul 2016, 01:02
Contact:

Re: String to number

12 Aug 2018, 09:07

You might be interested in this topic.
arcticir
Posts: 508
Joined: 17 Nov 2013, 11:32

Re: String to number

12 Aug 2018, 09:38

this topic, in addition to explaining why "Float()" cannot be accurately converted, is there any help for "accurate conversion type"?
User avatar
nnnik
Posts: 3049
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: String to number

12 Aug 2018, 10:26

AutoHotkeys floating point numbers are as precise as a double sized float (its the standar size).
If you want more precision you need a different type.
Recommends AHK Studio
lexikos
Posts: 6039
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: String to number

12 Aug 2018, 22:54

The conversion is accurate. The data type is not (for decimal fractions). You can't even choose to use or simulate a different data type if you're using DllCall. At some point the value must be converted to the type that the external function requires.

Return to “AutoHotkey v2 Development”

Who is online

Users browsing this forum: No registered users and 2 guests