AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to add commas to big numbers for separating thousandths?

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
EveOnline001



Joined: 23 Mar 2009
Posts: 27

PostPosted: Sat Apr 25, 2009 8:16 pm    Post subject: How to add commas to big numbers for separating thousandths? Reply with quote

I have: 8500250

I want: 8,500,250

How?


Thanks Very Happy
Back to top
View user's profile Send private message
Guest






PostPosted: Sun Apr 26, 2009 12:23 am    Post subject: Reply with quote

in the manual, look at stringright and stringtrimright.
Back to top
animeaime



Joined: 04 Nov 2008
Posts: 1045

PostPosted: Sun Apr 26, 2009 12:50 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Guest






PostPosted: Sun Apr 26, 2009 4:37 am    Post subject: Reply with quote

Here are two links that show how to do it.
1st using regex (by Laszlo)[url] http://www.autohotkey.com/forum/viewtopic.php?t=29596#184296[/url]

2nd using winapi (by SKAN) - it does it the same way windows does http://www.autohotkey.com/forum/topic35545.html#219023
Back to top
[VxE]



Joined: 07 Oct 2006
Posts: 3254
Location: Simi Valley, CA

PostPosted: Sun Apr 26, 2009 9:22 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group