Thousand-separator for MsgBox

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Peter2
Posts: 325
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 10 x64, AHK Version v1.1.33
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
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] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
Peter2
Posts: 325
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 10 x64, AHK Version v1.1.33
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
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] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: RandomBoy, Theda and 271 guests