AutoHotkey Community

It is currently May 26th, 2012, 5:46 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: April 25th, 2009, 9:16 pm 
Offline

Joined: March 23rd, 2009, 12:27 pm
Posts: 27
I have: 8500250

I want: 8,500,250

How?


Thanks :D


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 26th, 2009, 1:23 am 
in the manual, look at stringright and stringtrimright.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 26th, 2009, 1:50 am 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 26th, 2009, 5:37 am 
Here are two links that show how to do it.
1st using regex (by Laszlo)http://www.autohotkey.com/forum/viewtopic.php?t=29596#184296

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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 26th, 2009, 10:22 am 
Offline
User avatar

Joined: October 7th, 2006, 8:45 am
Posts: 3329
Location: Simi Valley, CA
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!


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: batto, BrandonHotkey, G. Sperotto, gamax92, Google Feedfetcher, Miguel, notsoobvious, rbrtryn and 69 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group