quatermass
Joined: 14 Dec 2005 Posts: 136
|
Posted: Fri Sep 19, 2008 10:04 am Post subject: Comma separated numbers |
|
|
Here is a function that takes a large number and pretties it up with commas.
Oddly this ability is not in AHK by default and when I'd program in BBC BASIC I got use to having it on tap.
| Code: | Prettynumber(n) {
RegRead,sThousands,HKEY_CURRENT_USER,Control Panel\International,sThousand
StringSplit, n, n, .
If (d := Mod(l := StrLen(Abs(n1)), 3)) and l > 3
n1 := RegExReplace(n1, "(\d{" . d . "})", "$1" . sThousands, "", 1)
Return, RegExReplace(n1, "(\d{3})(?!$)", "$1" . sThousands) . (n2 != "" ? "." . n2 : "")
}
|
So
| Code: | number := 123456789
pretty := Prettynumber(number)
msgbox, %pretty%
|
Gives you 123,456,789
Much easier to understand.
Oh and it should return the correct digit separator symbol.
e.g. 123.456.789 in those countries that use the dot instead of a comma.
Original function 'number()' taken and adapted from the SYSMON Script by MsgBox.
So full credit to him for creating it!
Share and enjoy.... _________________ Stuart Halliday |
|