Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Set Number Format


  • Please log in to reply
2 replies to this topic
JuniorHunt3R
  • Members
  • 3 posts
  • Last active: Sep 26 2013 11:12 AM
  • Joined: 09 Feb 2013

Hi guys,

 

I tried to search the forum, but I was not sure what was my real solution, so sincere apologies for causing annoyance if such case has been resolved before.

 

Apparently, I am making a script to add numbers from reports.

 

However, the values in the reports are such that instead of comma in thousands, the dot is used instead

 

Because of this, my script will read the value as

 

        33.300

 

instead of 

 

        33,300

 

I'm looking for a solution such that numbers greater than 999 can be read as thousands instead of decimals.

 

Extra information:

1. Numbers lesser than 1000 are fine

2. All numbers are whole numbers, thus no decimals involved

 

Thank you for the help, and once again, sincerest apologies for any annoyance caused!



Sjc1000
  • Members
  • 572 posts
  • Last active: Mar 11 2017 11:41 AM
  • Joined: 06 Feb 2012

Hi juniorhunt3r, Welcome to the AutoHotkey forum.

 

I have made a simple function that should suit your needs,

 

 

 

Number := 33.300


MsgBox, % DotToComma(Number)




DotToComma( Number )
{    RegExMatch( Number, "(\d+)\.(\d+[^$])", _ )
    Return _1 != "" ? _1 "," _2 : Number
}
 

 

If this doesn't work for some numbers please let me know and i will modify the code.


Sjc1000 - Insert inspirational quote here!

PLEASE find me on the IRC if you have questions. I'm never on the forum anymore.

 


flyingDman
  • Spam Officer
  • 2186 posts
  • Last active: Nov 07 2015 08:15 AM
  • Joined: 27 Feb 2009

For educational purposes the same can be obtained with stringreplace:

Number := 33.300
stringreplace,number,number,.,`,,1
msgbox % number

But more importantly, if your job is create a script that will add these numbers you do want commas either!.  So use stringreplace to delete all commas or dots. When it is time for a report, use something like this:

msgbox % KSep(10000)
KSep(x, d=2, s=",") {
	return RegExReplace(round(x,d), "\G\d+?(?=(\d{3})+(?:\D|$))", "$0" s)
}

Marine Corps Gen. Joseph Dunford told senators at his Joint Chiefs of Staff confirmation hearing : “If you want to talk about a nation that could pose an existential threat to the United States, I'd have to point to Russia. And if you look at their behavior, it's nothing short of alarming.”