Jump to content

Recommended Posts

Posted (edited)

Damn i have a lapse of memory, i need to add the dot for a number string, like:

1213 = 1.213

12345 = 12.345

745221 = 745.221

I have see into StringFormat example but i don't have find it, i'd like to search but i don't know how is called lol

Thanks and sorry

Edited by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Posted

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

I have see into StringFormat example but i don't have find it, i'd like to search but i don't know how is called lol

 

Yes i have understood but there isn't an example in StringFormat help for my case, or not?

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

  • Moderators
Posted

Terenz,

How do you decide where the decimal point is to be entered into the string of digits? :huh:

If you always want 3 digits after the decimal point then you can do this: ;)

ConsoleWrite(_AddPoint(1213) & @CRLF)
ConsoleWrite(_AddPoint(12345) & @CRLF)
ConsoleWrite(_AddPoint(745221) & @CRLF)

Func _AddPoint($iNumber)
    $iLen = StringLen($iNumber)
    Return StringMid($iNumber, 1, $iLen - 3) & "." & StringMid($iNumber, $iLen - 2)
EndFunc
M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

I wrote this some years ago:

#include <String.au3>
$i = 123456789
ConsoleWrite("$" & Display1000Seperator($i, ",", 1) & @LF)
$i = 9876543210.99
ConsoleWrite(Display1000Seperator($i) & @LF)
$i = 100
ConsoleWrite(Display1000Seperator($i) & @LF)
$i = "55555"
ConsoleWrite(Display1000Seperator($i) & @LF)
$i = "99999.123"
ConsoleWrite(Display1000Seperator($i) & @LF)

Func Display1000Seperator($iNumber, $sSeperator = ",", $bFloat = False) ;coded by UEZ 2012
    If $iNumber = "" Then SetError(1, 0, 0)
    Local $1000
    If IsInt(Number($iNumber)) Then
        $1000 = StringReverse(StringRegExpReplace(StringReverse($iNumber), ".{3}", "$0" & $sSeperator))
        If StringLeft($1000, 1) = $sSeperator Then $1000 = StringTrimLeft($1000, 1)
        If $bFloat Then Return $1000 & ".00"
        Return $1000
    ElseIf IsFloat(Number($iNumber)) Then
        Local $1000 =  StringReverse(StringRegExpReplace(StringReverse(StringRegExpReplace($iNumber, "(\d+)\..*", "$1")), ".{3}", "$0" & $sSeperator))
        If StringLeft($1000, 1) = $sSeperator Then $1000 = StringTrimLeft($1000, 1)
        Return $1000 & StringRegExpReplace($iNumber, "\d+(\..*)", "$1")
    EndIf
    Return SetError(2, 0, 0)
EndFunc

Might be useful for you.

 

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted

I have found what i need:

ConsoleWrite(_TabNum0(1000) & @CRLF)
ConsoleWrite(_TabNum0(10000) & @CRLF)
ConsoleWrite(_TabNum0(100000) & @CRLF)
ConsoleWrite(_TabNum0(10000000) & @CRLF & @CRLF)

ConsoleWrite(_StringAddThousandsSep(1000) & @CRLF)
ConsoleWrite(_StringAddThousandsSep(10000) & @CRLF)
ConsoleWrite(_StringAddThousandsSep(100000) & @CRLF)
ConsoleWrite(_StringAddThousandsSep(10000000) & @CRLF)

Func _TabNum0($tn) ; Author: dwerf
    Return StringRegExpReplace($tn, '(\A\d{1,3}(?=(\d{3})+\z)|\d{3}(?=\d))', '\1.')
EndFunc

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   ;<==> _StringAddThousandsSep()

Probably i'll use the first function ( TabNum0 ) but other suggestion are welcome

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

  • Moderators
Posted (edited)

Terenz,

Ah, the continental "thousand separator" dot and not a "decimal point" - it always helps if you are clear about what you are trying to do. ;)

M23

Edit: I feel I should point out that the thread title has since been altered. :whistle:

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

Well if the title was "how to add the thousand separator" i think was better but the fault is my memory lapse :sweating:

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...