Page 1 of 1
[v2] String to number
Posted: 12 Aug 2018, 07:55
by arcticir
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"]
Re: String to number
Posted: 12 Aug 2018, 08:10
by nnnik
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.)
Re: String to number Topic is solved
Posted: 12 Aug 2018, 08:17
by Helgef
There are two (suitable) functions available, integer and float.
Re: String to number
Posted: 12 Aug 2018, 08:24
by arcticir
Yes, but as some DLL parameters, need to convert.
Re: String to number
Posted: 12 Aug 2018, 08:27
by arcticir
Helgef wrote:There are two (suitable) functions available, integer and float.
Can you link the addresses of these two functions? I can't find.
Re: String to number
Posted: 12 Aug 2018, 08:30
by guest3456
Re: String to number
Posted: 12 Aug 2018, 08:52
by arcticir
thank you very much. My "help document" is too old.
Re: String to number
Posted: 12 Aug 2018, 09:02
by arcticir
One problem is that its conversion is not accurate, it is very bad when converting JSON data:
Float("6.9") ;==>6.9000000000000004
Re: String to number
Posted: 12 Aug 2018, 09:07
by Helgef
You might be interested in
this topic.
Re: String to number
Posted: 12 Aug 2018, 09:38
by arcticir
this topic, in addition to explaining why "Float()" cannot be accurately converted, is there any help for "accurate conversion type"?
Re: String to number
Posted: 12 Aug 2018, 10:26
by nnnik
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.
Re: String to number
Posted: 12 Aug 2018, 22:54
by lexikos
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.