Thousand-separator for MsgBox

Get help with using AutoHotkey and its commands and hotkeys
Peter2
Posts: 252
Joined: 21 Sep 2014, 14:38
Location: CH

Thousand-separator for MsgBox

21 Oct 2015, 03:43

Is there a simple / standard way to display numbers with thousand-separators (like Excel):

Msgbox % 123456*2 -> "246.912,00"
Peter (AHK Beginner) / Win 7 x64, AHK Version v1.1.22.xx
User avatar
jNizM
Posts: 2639
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: Thousand-separator for MsgBox

21 Oct 2015, 03:59

Nope but I got a finished function for it:

Code: Select all

MsgBox % FormatNumber(123456 * 2)            ; ==> 246.912,00   (LANG_USER_DEFAULT | SUBLANG_DEFAULT) [for me GER]
MsgBox % FormatNumber(123456 * 2, 0x0409)    ; ==> 246,912.00   (LANG_ENGLISH      | SUBLANG_ENGLISH_US)
MsgBox % FormatNumber(123456 * 2, 0x0407)    ; ==> 246.912,00   (LANG_GERMAN       | SUBLANG_GERMAN)
 
FormatNumber(num, locale := 0x0400)    ; http://msdn.com/library/dd318110(vs.85,en-us)
{
    size := DllCall("GetNumberFormat", "UInt", locale, "UInt", 0, "Ptr", &num, "Ptr", 0, "Ptr", 0, "Int", 0)
    VarSetCapacity(buf, size * (A_IsUnicode ? 2 : 1), 0)
    DllCall("GetNumberFormat", "UInt", locale, "UInt", 0, "Ptr", &num, "Ptr", 0, "Str", buf, "Int", size)
    return buf
}

ref:
- GetNumberFormat function
- Language Identifier Constants and Strings
[AHK] 1.1.32.00 x64 Unicode | [WIN] 10 Pro (Version 2004) x64 | [GitHub] Profile
Donations are appreciated if I could help you
Peter2
Posts: 252
Joined: 21 Sep 2014, 14:38
Location: CH

Re: Thousand-separator for MsgBox

21 Oct 2015, 05:26

Thanks for the fine script and the good documentation.
Peter (AHK Beginner) / Win 7 x64, AHK Version v1.1.22.xx
User avatar
jNizM
Posts: 2639
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: Thousand-separator for MsgBox

22 Oct 2015, 08:56

Alternate with GetNumberFormatEx (only Vista or later)

Code: Select all

MsgBox % FormatNumberEx(123456 * 2)             ; ==> 246.912,00   (for me GER)
MsgBox % FormatNumberEx(123456 * 2, "en-US")    ; ==> 246,912.00   (ENGLISH_US)
MsgBox % FormatNumberEx(123456 * 2, "de")       ; ==> 246.912,00   (GERMAN)

FormatNumberEx(num, locale := "!x-sys-default-locale")    ; http://msdn.com/library/dd318113(vs.85,en-us)
{
    size := DllCall("GetNumberFormatEx", "Ptr", &locale, "UInt", 0, "Ptr", &num, "Ptr", 0, "Ptr", 0, "Int", 0)
    VarSetCapacity(buf, size * (A_IsUnicode ? 2 : 1), 0)
    DllCall("GetNumberFormatEx", "Ptr", &locale, "UInt", 0, "Ptr", &num, "Ptr", 0, "Str", buf, "Int", size)
    return buf
}

ref:
- GetNumberFormatEx function
- Locale Names
[AHK] 1.1.32.00 x64 Unicode | [WIN] 10 Pro (Version 2004) x64 | [GitHub] Profile
Donations are appreciated if I could help you

Return to “Ask For Help”

Who is online

Users browsing this forum: Herchi, Smile_ and 67 guests