Expand Minimize

GetNumberFormat function

Formats a number string as a number string customized for a locale specified by identifier.

Note  For interoperability reasons, the application should prefer the GetNumberFormatEx function to GetNumberFormat because Microsoft is migrating toward the use of locale names instead of locale identifiers for new locales. Any application that runs only on Windows Vista and later should use GetNumberFormatEx.

Syntax


int GetNumberFormat(
  _In_       LCID Locale,
  _In_       DWORD dwFlags,
  _In_       LPCTSTR lpValue,
  _In_opt_   const NUMBERFMT *lpFormat,
  _Out_opt_  LPTSTR lpNumberStr,
  _In_       int cchNumber
);

Parameters

Locale [in]

Locale identifier that specifies the locale. You can use the MAKELCID macro to create a locale identifier or use one of the following predefined values.

dwFlags [in]

Flags controlling the operation of the function. The application must set this parameter to 0 if lpFormat is not set to NULL. In this case, the function formats the string using user overrides to the default number format for the locale. If lpFormat is set to NULL, the application can specify LOCALE_NOUSEROVERRIDE to format the string using the system default number format for the specified locale.

Caution  Use of LOCALE_NOUSEROVERRIDE is strongly discouraged as it disables user preferences.

lpValue [in]

Pointer to a null-terminated string containing the number string to format. This string can only contain the following characters. All other characters are invalid. The function returns an error if the string indicated by lpValue deviates from these rules.

  • Characters "0" through "9".
  • One decimal point (dot) if the number is a floating-point value.
  • A minus sign in the first character position if the number is a negative value.
lpFormat [in, optional]

Pointer to a NUMBERFMT structure that contains number formatting information, with all members set to appropriate values. If this parameter does is not set to NULL, the function uses the locale only for formatting information not specified in the structure, for example, the locale-specific string value for the negative sign.

lpNumberStr [out, optional]

Pointer to a buffer in which this function retrieves the formatted number string.

cchNumber [in]

Size, in TCHAR values, for the number string buffer indicated by lpNumberStr. Alternatively, the application can set this parameter to 0. In this case, the function returns the required size for the number string buffer, and does not use the lpNumberStr parameter.

Return value

Returns the number of TCHAR values retrieved in the buffer indicated by lpNumberStr if successful. If the cchNumber parameter is set to 0, the function returns the number of characters required to hold the formatted number string, including a terminating null character.

The function returns 0 if it does not succeed. To get extended error information, the application can call GetLastError, which can return one of the following error codes:

  • ERROR_INSUFFICIENT_BUFFER. A supplied buffer size was not large enough, or it was incorrectly set to NULL.
  • ERROR_INVALID_FLAGS. The values supplied for flags were not valid.
  • ERROR_INVALID_PARAMETER. Any of the parameter values was invalid.
  • ERROR_OUTOFMEMORY. Not enough storage was available to complete this operation.

Remarks

This function can retrieve data from custom locales. Data is not guaranteed to be the same from computer to computer or between runs of an application. If your application must persist or transmit data, see Using Persistent Locale Data.

When the ANSI version of this function is used with a Unicode-only locale identifier, the function can succeed because the operating system uses the system code page. However, characters that are undefined in the system code page appear in the string as a question mark (?).

Requirements

Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Header

Winnls.h (include Windows.h)

Library

Kernel32.lib

DLL

Kernel32.dll

Unicode and ANSI names

GetNumberFormatW (Unicode) and GetNumberFormatA (ANSI)

See also

National Language Support
National Language Support Functions
GetNumberFormatEx
NUMBERFMT

 

 

Community Additions

ADD
Show:
© 2014 Microsoft