Is there a simple / standard way to display numbers with thousand-separators (like Excel):
Msgbox % 123456*2 -> "246.912,00"
Thousand-separator for MsgBox
Thousand-separator for MsgBox
Peter (AHK Beginner) / Win 10 x64, AHK Version v1.1.33
Re: Thousand-separator for MsgBox
Nope but I got a finished function for it:
ref:
- GetNumberFormat function
- Language Identifier Constants and Strings
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
Re: Thousand-separator for MsgBox
Thanks for the fine script and the good documentation.
Peter (AHK Beginner) / Win 10 x64, AHK Version v1.1.33
Re: Thousand-separator for MsgBox
Alternate with GetNumberFormatEx (only Vista or later)
ref:
- GetNumberFormatEx function
- Locale Names
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