String to number

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

String to number

Post by arcticir » 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: 3330
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: String to number

Post by nnnik » 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: 3190
Joined: 17 Jul 2016, 01:02
Contact:

Re: String to number

Post by Helgef » 12 Aug 2018, 08:17

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

Re: String to number

Post by arcticir » 12 Aug 2018, 08:24

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

Re: String to number

Post by arcticir » 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: 2419
Joined: 09 Oct 2013, 10:31

Re: String to number

Post by guest3456 » 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: 542
Joined: 17 Nov 2013, 11:32

Re: String to number

Post by arcticir » 12 Aug 2018, 08:52

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

Re: String to number

Post by arcticir » 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: 3190
Joined: 17 Jul 2016, 01:02
Contact:

Re: String to number

Post by Helgef » 12 Aug 2018, 09:07

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

Re: String to number

Post by arcticir » 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: 3330
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: String to number

Post by nnnik » 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: 6175
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: String to number

Post by lexikos » 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.
Post Reply

Return to “AutoHotkey v2 Development”