Search code examples
winapilocalizationvb6

How to get the Windows "Digit Grouping" setting


In the Windows Regional control panel is a "Digit Grouping" setting, which indicates whether the Indian numbering system is used, where the thousands separator character groups the first three digits to the left of the decimal together, and thereafter every two digits, vs. the more common grouping where every three digits to the left the decimal are grouped together.

How can I get that setting in VB6?

Or, alternatively, what is the best way to determine when to use that Indian numbering system?


Solution

  • Private Const LOCALE_SGROUPING = &H10
    Private Const LOCALE_USER_DEFAULT = &H400
    Private Declare Function GetLocaleInfo Lib "kernel32" Alias "GetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String, ByVal cchData As Long) as Long
    
    Private Function Grouping() As String
      Dim retVal As Long, sBuf As String
      sBuf = String(255, vbNullChar)
      retVal = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SGROUPING, sBuf, Len(sBuf))
      Grouping = Left$(sBuf, retVal - 1)
    End Function
    

    Example: will output: 3;0 for 123.456,789 and 3;2;0 for 12.34.56,789