NoizeBit Posted August 29, 2015 Share Posted August 29, 2015 (edited) Hello,Once again, I'd like to ask for some help. I'd like to have 10,000.00 as a result here instead of 100,00.00. What do I need to change?StringRegExpReplace("10000.00", '(\A\d{1,3}(?=(\d{3})+\z)|\d{3}(?=\d))', '\1,')The string might change from time to time to 1000.00 or 1000000.00, so it would be great to have this thousand separator all the time.Thanks! Edited August 29, 2015 by NoizeBit Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 29, 2015 Moderators Share Posted August 29, 2015 (edited) NoizeBit,I still use the old function that was removed a while ago:expandcollapse popup;=============================================================================== ; Function Name: _StringAddThousandsSep() ; Description: Returns the original numbered string with the Thousands and or Decimal delimiter(s) inserted. ; Syntax: _StringAddThousandsSep($s_string[, $i_convert_lcid = -1[, $i_current_lcid = -1]]) ; Parameter(s): $s_string - The string to be converted. ; $i_convert_lcid - Optional: Default or -1 wll be the User default locale else: ; LCID of what you want to convert number to. ; $i_current_lcid - Optional: Default or -1 wll be the User default locale else: ; LCID number was converted with originally. ; Requirement(s): ; Return Value(s): - Success - The string with Thousands delimiter added. ; - Failure - Returns empty string and sets @error to 1. ; Author(s): SmOke_N, Valik, GEOSoft ; Modification(s): ; Note(s): Changes are script breaking after AutoIt version 3.3.0.0 ; LCID numbers can be obtained by pre-pending the OSLang codes in the help file appendix with "0x". ; Example(s): ;=============================================================================== $sRet = _StringAddThousandsSep("10000.00") ConsoleWrite($sRet & @CRLF) Func _StringAddThousandsSep($s_string, $i_convert_lcid = -1, $i_current_lcid = -1) ; $LOCALE_USER_DEFAULT = 0x0400 If $i_current_lcid = -1 Or $i_current_lcid = Default Then $i_current_lcid = 0x0400 If $i_convert_lcid = -1 Or $i_convert_lcid = Default Then $i_convert_lcid = 0x0400 ; Get lcid decimal and thousands separators Local $t_buff_tmp = DllStructCreate("char[4]") DllCall("kernel32.dll", "int", "GetLocaleInfo", "int", $i_current_lcid, _ "int", 0x0E, "ptr", DllStructGetPtr($t_buff_tmp), "int", 4) If @error Then Return SetError(1, 0, "") Local $s_cur_dec = DllStructGetData($t_buff_tmp, 1) DllCall("kernel32.dll", "int", "GetLocaleInfo", "int", $i_convert_lcid, _ "int", 0x0E, "ptr", DllStructGetPtr($t_buff_tmp), "int", 4) If @error Then Return SetError(1, 0, "") Local $s_con_dec = DllStructGetData($t_buff_tmp, 1) DllCall("kernel32.dll", "int", "GetLocaleInfo", "int", $i_convert_lcid, _ "int", 0x0F, "ptr", DllStructGetPtr($t_buff_tmp), "int", 4) If @error Then Return SetError(1, 0, "") Local $s_con_tho = DllStructGetData($t_buff_tmp, 1) ; For later formatting Local $i_number = StringRegExpReplace($s_string, "(\" & $s_cur_dec & "\d+\z)|(^-|\d+)|(\D)", "$2") Local $i_dec = StringRegExpReplace($s_string, "(.+?\" & $s_cur_dec & ")(\d+\z)", "$2") If @extended = 0 Then $i_dec = "" Local $i_str_len = StringLen($s_string) * 4 Local $t_numberfmt = DllStructCreate("uint;uint;uint;ptr;ptr;uint") Local $t_thousands = DllStructCreate("wchar[2]") Local $t_decimal = DllStructCreate("wchar[2]") Local $t_buffer = DllStructCreate("wchar[" & $i_str_len & "]") DllStructSetData($t_thousands, 1, $s_con_tho) DllStructSetData($t_decimal, 1, $s_con_dec) DllStructSetData($t_numberfmt, 3, 3) DllStructSetData($t_numberfmt, 4, DllStructGetPtr($t_decimal)) DllStructSetData($t_numberfmt, 5, DllStructGetPtr($t_thousands)) DllStructSetData($t_numberfmt, 6, 1) DllCall("kernel32.dll", "int", "GetNumberFormatW", _ "int", $i_convert_lcid, "int", 0, _ "wstr", $i_number, "ptr", DllStructGetPtr($t_numberfmt), _ "ptr", DllStructGetPtr($t_buffer), "int", $i_str_len) If $i_dec = "" Then $s_con_dec = "" Return DllStructGetData($t_buffer, 1) & $s_con_dec & $i_dec EndFunc ;==>_StringAddThousandsSepM23 Edited August 30, 2015 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
guinness Posted August 29, 2015 Share Posted August 29, 2015 (edited) There is also a regex version by @AZJIO somewhere on the forum. The thousandth separator is a funny thing, because in some countries a comma (,) represents a decimal character. For example in the UK and USA, 1,000 is one thousand, whereas somewhere else it would be 1.000. Weird isn't it! Edited August 29, 2015 by guinness UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
iamtheky Posted August 29, 2015 Share Posted August 29, 2015 (edited) If I had that need I would end up with something more like: msgbox(0, '' , _AddThousandsSep("1000000000.98")) ; default comma msgbox(0, '' , _AddThousandsSep("10000.00" , ".")) ; specify period msgbox(0, '' , _AddThousandsSep("1987" , "|")) ; specify pipe Func _AddThousandsSep($sString , $sSep = ",") $aString = stringsplit($sString , "." , 2) $nMax = round(stringlen($aString[0]) / 3) local $aNum[$nMax] $sWorking = $aString[0] $sOut = "" for $i = 0 to $nMax If stringlen($sWorking) > 2 Then $sOut = $sSep & stringright($sWorking , 3) & $sOut $sWorking = stringtrimright($sWorking , 3) Else $sOut = ubound($aString) > 1 ? stringright($sWorking , stringlen($sWorking)) & $sOut & "." & $aString[1] : stringright($sWorking , stringlen($sWorking)) & $sOut exitloop EndIf next return $sOut EndFunc This one may be the dirtiest kind of clean: *for prices...anything out to the tenths;~ $sString = "1000000000.98" ;~ $sString = "10000.00" ;~ $sString = "1987" msgbox(0, '' , stringreverse(stringregexpreplace(stringreverse($sString) , "(\d\d\d)" , "$1,"))) Edited August 29, 2015 by boththose ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
mikell Posted August 29, 2015 Share Posted August 29, 2015 There is also a regex version by @AZJIO somewhere on the forum.Yes, this is a typical exercise for regex I used it when learning the \G anchor$sInput = "1234567890.1234" $sOutput = StringRegExpReplace($sInput, '\G(\d+?)(?=(\d{3})+(\D|$))', '$1,') MsgBox(0, "", $sInput & @crlf & $sOutput) czardas, therks and jguinch 3 Link to comment Share on other sites More sharing options...
guinness Posted August 29, 2015 Share Posted August 29, 2015 Is that your version of AZJIO's. If AZJIO's please provide a backlink for attribution. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
mikell Posted August 29, 2015 Share Posted August 29, 2015 No, it's not AZJIO's solution (I don't know it and its link), it's another one Link to comment Share on other sites More sharing options...
NoizeBit Posted August 30, 2015 Author Share Posted August 30, 2015 Thank you guys for the contributions, I'll try all of them. Thanks again Link to comment Share on other sites More sharing options...
NoizeBit Posted August 30, 2015 Author Share Posted August 30, 2015 There is also a regex version by @AZJIO somewhere on the forum. The thousandth separator is a funny thing, because in some countries a comma (,) represents a decimal character. For example in the UK and USA, 1,000 is one thousand, whereas somewhere else it would be 1.000. Weird isn't it!Exactly, in my country 1,000.00 would look like 1.000,00 - I'd say annoying at best if you're dealing with currencies all day long Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 30, 2015 Moderators Share Posted August 30, 2015 NoizeBit,The function I posted should get that right as it checks for the language settings. All you need to do is set the correct $i_convert_lcid & $i_current_lcid values and you (should) get the correct separators for that language - certainly worked for me when I tested just now.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
jguinch Posted August 30, 2015 Share Posted August 30, 2015 (edited) Really nice Mikell !Another way, with _WinAPI_CreateNumberFormatInfo :#include <WinAPILocale.au3> $sInput = "-1234567890.2244" $sOutput = _WinAPI_CreateNumberFormatInfo ( StringLen( StringRegExpReplace($sInput, "\d+\.?(.*)", "$1")), 0, 3, ".", ",", 1 ) MsgBox(0, "", _WinAPI_GetNumberFormat(0, $sInput,$sOutput )) Edited August 30, 2015 by jguinch Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
mikell Posted August 30, 2015 Share Posted August 30, 2015 (edited) Melba,"$en" flag = 1 means en notation, 0 means european $sInput1 = "1234567890,1234" $sOutput1 = _StringAddThousandsSep($sInput1, 0) MsgBox(0, "", $sInput1 & @crlf & $sOutput1) $sInput2 = "-1234567890.1234" $sOutput2 = _StringAddThousandsSep($sInput2, 1) MsgBox(0, "", $sInput2 & @crlf & $sOutput2) Func _StringAddThousandsSep($s_string, $en) Return StringRegExpReplace($s_string, '\G(-?\d+?)(?=(\d{3})+(\D|$))', "$1" & Chr($en*44+(not $en)*46)) ; or this to avoid error checking on the flag ; Return StringRegExpReplace($s_string, '\G(-?\d+?)(?=(\d{3})+(\D|$))', "$1" & (($en = 0) ? "," : ".")) EndFuncEditjguinch, what if there are no decimals ? Edited August 30, 2015 by mikell Link to comment Share on other sites More sharing options...
jguinch Posted August 30, 2015 Share Posted August 30, 2015 @Mikell : edited.Try yours with a negative number Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
mikell Posted August 30, 2015 Share Posted August 30, 2015 Last post edited Link to comment Share on other sites More sharing options...
AZJIO Posted August 31, 2015 Share Posted August 31, 2015 http://autoit-script.ru/index.php?topic=3814.msg27783#msg27783 My other projects or all Link to comment Share on other sites More sharing options...
NoizeBit Posted August 31, 2015 Author Share Posted August 31, 2015 NoizeBit,The function I posted should get that right as it checks for the language settings. All you need to do is set the correct $i_convert_lcid & $i_current_lcid values and you (should) get the correct separators for that language - certainly worked for me when I tested just now.M23Thanks Melba, I'll definitely give it a shot, seems like what I'm looking for. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now