Adding Commas to GUI Number Variables

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
dmax52
Posts: 4
Joined: 25 Jul 2021, 13:18

Adding Commas to GUI Number Variables

28 Jul 2021, 21:25

I've seen a few old posts on this (using regex) but I was unable to make sense of the formula and how to construct it.

I currently have this line of code:

Code: Select all

AMT := Round(PD * PE,2)
if (SC = "") {
Send {$}%AMT%
} else {
SC := SC
OC := round(SC + AMT,2)
Send {$}%OC%
}
%PD%, %PE%, and %SC% are entered by the user in a GUI.

Say %OC% = 1000.00, how could I get it to output 1,000.00?

Thank you in advance!
Rohwedder
Posts: 7647
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Adding Commas to GUI Number Variables

29 Jul 2021, 03:53

Hallo,
try:

Code: Select all

AMT := Round(PD * PE,2)
if (SC = "") {
Send {$}%AMT%
} else {
SC := SC
OC := round(SC + AMT,2)
Send,% "$" ThSep(OC)
}

ThSep(x, s=",")
{ ; s = thousands separator
	Return, RegExReplace(x, "\G\d+?(?=(\d{3})+(?:\D|$))", "$0" s)
} ; https://autohotkey.com/board/topic/50019-add-thousands-separator/
dmax52
Posts: 4
Joined: 25 Jul 2021, 13:18

Re: Adding Commas to GUI Number Variables

29 Jul 2021, 11:52

Rohwedder wrote:
29 Jul 2021, 03:53
Hallo,
try:

Code: Select all

AMT := Round(PD * PE,2)
if (SC = "") {
Send {$}%AMT%
} else {
SC := SC
OC := round(SC + AMT,2)
Send,% "$" ThSep(OC)
}

ThSep(x, s=",")
{ ; s = thousands separator
	Return, RegExReplace(x, "\G\d+?(?=(\d{3})+(?:\D|$))", "$0" s)
} ; https://autohotkey.com/board/topic/50019-add-thousands-separator/
Thank you so much <3, worked perfectly!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: joefiesta, RussF and 287 guests