Jump to content

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

Add Thousands Separator


  • Please log in to reply
21 replies to this topic
elseif
  • Members
  • 4 posts
  • Last active: Aug 04 2014 11:44 AM
  • Joined: 16 Aug 2013

thank you very much.



Drugwash
  • Members
  • 1078 posts
  • Last active: May 24 2016 04:20 PM
  • Joined: 07 Sep 2008
Uselessly browsing the web for a straightforward API to do this, the Duck landed me here. I'll settle for this function for now. However, to give something back I've put together the right - I believe - method to get current user's default thousands separator. This can of course be overriden as previously, by specifying a character for the 's' parameter. (or string up to three chars, according to MSDN, but that needs further tweaking) The function would look like this:
ThousandsSep(x, s="")
{
if !s
if DllCall("GetLocaleInfo"
	, "UInt", DllCall("GetUserDefaultLCID", "UInt")	; LCID
	, "UInt", 0xF							; LCType LOCALE_STHOUSAND
	, "UIntP", sep:="000"					; lpLCData
	, "UInt", 4)							; cchData
s := Chr(sep)
return RegExReplace(x, "\G\d+?(?=(\d{3})+(?:\D|$))", "$0" s)
}

(AHK 1.0.48.05 and Win98SE) forever | My scripts are here


Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012

Uselessly browsing the web for a straightforward API to do this, the Duck landed me here. I'll settle for this function for now. However, to give something back I've put together the right - I believe - method to get current user's default thousands separator. This can of course be overriden as previously, by specifying a character for the 's' parameter. (or string up to three chars, according to MSDN, but that needs further tweaking) The function would look like this:

ThousandsSep(x, s="")
{
if !s
if DllCall("GetLocaleInfo"
	, "UInt", DllCall("GetUserDefaultLCID", "UInt")	; LCID
	, "UInt", 0xF							; LCType LOCALE_STHOUSAND
	, "UIntP", sep:="000"					; lpLCData
	, "UInt", 4)							; cchData
s := Chr(sep)
return RegExReplace(x, "\G\d+?(?=(\d{3})+(?:\D|$))", "$0" s)
}

Thanks, I'll test! Hope you are off Win 98 and onto the Free Win 10 now. ;)



Drugwash
  • Members
  • 1078 posts
  • Last active: May 24 2016 04:20 PM
  • Joined: 07 Sep 2008

Nope, I'm good with 98SE, thank you. At the rate WinX communicates each and every move and word (literally) to the mothership my monthly download quota would be depleted in a couple of days at most. And my brains would also be literally splattered across the walls. ;)


(AHK 1.0.48.05 and Win98SE) forever | My scripts are here


Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012

I am looking forward to your creative scripts for average users like me who are still on XP and have no intention upgrading to Win 10 even though that option may be offered for free. ;)



jNizM
  • Members
  • 928 posts
  • Last active: Jan 12 2018 09:23 AM
  • Joined: 01 Aug 2012
#NoEnv
#SingleInstance Force
 
Gui, Add, Edit, w200 0x2000 gTEST vInputNum
Gui, Add, Edit, wp
Gui, Show
return
 
TEST:
    Gui, Submit, NoHide
    GuiControl,, Edit2, % Decimal_Mark(InputNum)
return
 
GuiClose:
GuiEscape:
    ExitApp
 
Decimal_Mark(num, locale := 0x0400) ; https://msdn.microsoft.com/en-us/library/dd318110.aspx
{
    size := DllCall("GetNumberFormat", "UInt", locale, "UInt", 0, "Str", num, "Ptr", 0, "Ptr", 0, "Int", 0)
    VarSetCapacity(buf, size * (A_IsUnicode ? 2 : 1), 0)
    DllCall("GetNumberFormat", "UInt", locale, "UInt", 0, "Str", num, "Ptr", 0, "Str", buf, "Int", size)
    return SubStr(buf, 1, StrLen(buf) - 3)
}

/*
Language Identifier Constants and Strings
https://msdn.microsoft.com/en-us/library/dd318693.aspx

e.g.
0x0400 LOCALE_SYSTEM_DEFAULT
0x0809 [en-GB] English (United Kingdom)
0x0409 [en-US] English (United States)
0x0407 [de-DE] German (Germany)
*/

[AHK] 1.1.27.04 x64 Unicode | [WIN] 10 Pro (Version 1709)
My GitHub Profile | Donations are appreciated if I could help you

Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012

Very nice! ;)