hi all,
i used ControlGetText to grab a number but the number came in a format like 10.1k(means 10100 ?), 91.158k, 130.332k, etc
my question, is there an easy way to translate back to numerical numbers?
much thanks.
numbers in X.Xk back to numerical numbers Topic is solved
numbers in X.Xk back to numerical numbers
Last edited by ronkwan on 19 Oct 2017, 00:32, edited 1 time in total.
Re: numbers in X.Xk back to numberical numbers
Code: Select all
ControlGetText, number, ...
number := StrReplace(number,"k","00")
MsgBox % number
Re: numbers in X.Xk back to numberical numbers Topic is solved
I've had a go at some RegEx for this, although to write '130.332k' would seem very unusual, in case you have a link or a copy of some original text.
Perhaps it's the European style of writing numbers, where '.' means ','? But then you have '10.1k' example which would contradict this.
Anyhow, I would use a script such as this with caution, in case it modifies some of the other text unintentionally.
Perhaps it's the European style of writing numbers, where '.' means ','? But then you have '10.1k' example which would contradict this.
Anyhow, I would use a script such as this with caution, in case it modifies some of the other text unintentionally.
Code: Select all
q::
vText := "10.1k 91.158k 130.332k"
vTextOrig := vText
vText := RegExReplace(vText, "\.(\d{1})k", "$100")
vText := RegExReplace(vText, "\.(\d{2})k", "$10")
vText := RegExReplace(vText, "\.(\d{3})k", "$1")
MsgBox, % vTextOrig "`r`n" vText
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: numbers in X.Xk back to numberical numbers
Assuming the k means 1000, I would use variable:=RegExReplace(variable,"[\.k]","") then multiply the result by 1000 (even in the same expression). You can even add in a check that your remaining number is numerical. If var is number, potentially. (Also any commas have to be separated out; also I'm considering this to be numerical...)
Here's a quick test, which adds in a comma separator.
Or to shorten this up with the ternary operator and || (OR) operators, with a little change in the Mod logic (dropping the ! operator), and also removing the assignment of the StrLen() to a variable (which technically makes AHK do a bit more work I believe; no noticeable impact at these short strings), and also making sure to clear the final_answer variable before you start this process (or else pressing ^8 twice in a row in this example would've resulted in 91,158,00091,158,000):
Here's a quick test, which adds in a comma separator.
Code: Select all
^8::
string:="91.158k"
string:=RegExReplace(string,"[\.k]","")*1000
length:=StrLen(string)
Loop, Parse, string
{
If A_Index=1
final_answer.=A_LoopField
else If !Mod(length+1-A_Index,3)
final_answer.="," A_LoopField
else
final_answer.=A_LoopField
}
MsgBox % final_answer
return
Code: Select all
^8::
string:="91.158k", final_answer.=""
string:=RegExReplace(string,"[\.k]","")*1000
Loop, Parse, string
final_answer.=(A_Index=1 || Mod(StrLen(string)+1-A_Index,3)) ? A_LoopField : "," A_LoopField
MsgBox % final_answer
return
Re: numbers in X.Xk back to numberical numbers
Confirmed, regarding the "thousand separator" (at least for Germany).Perhaps it's the European style of writing numbers, where '.' means ','? But then you have '10.1k' example which would contradict this.
Something that can be easily checked with changing the currency format in Excel.
10.1k = 10.100 = 10000
12.345,67 €
Re: numbers in X.Xk back to numberical numbers
much thanks BoBo, jeeswg and Exaskryz.
the number is extracted from a 3rd party delphi program which I have no control over with.
the number goes from 1 to around 150k on every business day. from 1 to 9999, it displays normal numerical digits without any problem until it hits 10k, 10.001k, 10.01k, 10.1k etc
the examples i provided are real original text. i am trying out your ideas and i think you have provided enough information for me to solve the problem.
thanks again.
the number is extracted from a 3rd party delphi program which I have no control over with.
the number goes from 1 to around 150k on every business day. from 1 to 9999, it displays normal numerical digits without any problem until it hits 10k, 10.001k, 10.01k, 10.1k etc
the examples i provided are real original text. i am trying out your ideas and i think you have provided enough information for me to solve the problem.
thanks again.
Who is online
Users browsing this forum: No registered users and 344 guests