 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
EveOnline001
Joined: 23 Mar 2009 Posts: 27
|
Posted: Sat Apr 25, 2009 8:16 pm Post subject: How to add commas to big numbers for separating thousandths? |
|
|
I have: 8500250
I want: 8,500,250
How?
Thanks  |
|
| Back to top |
|
 |
Guest
|
Posted: Sun Apr 26, 2009 12:23 am Post subject: |
|
|
| in the manual, look at stringright and stringtrimright. |
|
| Back to top |
|
 |
animeaime
Joined: 04 Nov 2008 Posts: 1045
|
Posted: Sun Apr 26, 2009 12:50 am Post subject: |
|
|
You can use this RegEx - works for both integer and float values.
| Code: | value := "8500250"
value := RegExReplace(value, "(\d)(?=(?:\d{3})+(?:\.|$))", "$1,")
;outputs 8,500,250
MsgBox, % value
value := "8500250.123"
value := RegExReplace(value, "(\d)(?=(?:\d{3})+(?:\.|$))", "$1,")
;outputs 8,500,250.123
MsgBox, % value
|
_________________ As always, if you have any further questions, don't hesitate to ask.
Add OOP to your scripts via the Class Library. Check out my scripts. |
|
| Back to top |
|
 |
Guest
|
|
| Back to top |
|
 |
[VxE]
Joined: 07 Oct 2006 Posts: 3254 Location: Simi Valley, CA
|
Posted: Sun Apr 26, 2009 9:22 am Post subject: |
|
|
And here's a normal AHK way to add commas to a number. | Code: | AddCommas(n)
{
StringSplit, d, n, .
Loop, % StrLen(d1)
x := SubStr(d1, 1-A_Index, 1), c := x . (A_Index>1 && !Mod(A_Index-1,3) ? "," : "") . c
return c . (d0=2 ? "." d2 : "")
} |
_________________ Ternary (a ? b : c) guide TSV Table Manipulation Library
Post code inside [code][/code] tags! |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|