3ds Max C++ API Reference
Locale Handler APIs

3ds Max provides APIs that help render correctly and consistently locale (region) specific information such as floating point numbers, date and time. More...

Classes

class  MaxLocaleHandler
 Helper class for setting locale temporarily. More...
 

Functions

UtilExport const _locale_t & GetCNumericLocale ()
 Returns a C numeric locale specification. More...
 
UtilExport const _locale_t & GetUserLocale ()
 Returns the user locale cached at the start of 3ds Max. More...
 

Detailed Description

3ds Max provides APIs that help render correctly and consistently locale (region) specific information such as floating point numbers, date and time.

Use the GetUserLocale() API to facilitate displaying floating point, date and time values in 3ds Max's user interface. These need to respect the current locale settings, i.e. the current user's regional preferences. Use GetCNumericLocale() or class MaxLocaleHandler to read and write data to text files in a locale independent format, such as a minimal ANSI conforming environment for C translation, known as "C" locale

Function Documentation

◆ GetCNumericLocale()

UtilExport const _locale_t& GetCNumericLocale ( )

Returns a C numeric locale specification.

This method should be used when writing or reading locale independent data to or from a file. Floating point values need to be stored in a locale independent representation in order to allow them to be used on computers using different locales or regional settings, i.e. they must always be written, read or formatted using dot ('.') as decimal separator. The locale object returned by this function can be used with APIs that use a locale parameter to interpret the data they read, write or format. Examples of such APIs are: _stscanf_l(), _sntprintf_s_l(), TSTR::printf_l(), BaseTextReader::Printf_l(), etc

..

// Setting a C-numeric locale ensures that a floating point number is written with
// a "." as decimal separator, regardless of the regional settings currently in effect
TextFile::ReaderWriter file;
BinaryStreamMemory buffer(malloc(1), 0, realloc, free);
file.Open(&buffer, BinaryStream::ParseStreamMode(_T("rw")), 0, TextFile::Unchanged, false)
file.Printf_l(_T("%5.2f\n"), GetCNumericLocale(), 100.321); // should write 100.321 even when the current locale settings are using "," as decimal separator
file.Close();
..
UtilExport const _locale_t & GetCNumericLocale()
Returns a C numeric locale specification.
@ Unchanged
When reading or writing a file, don't alter the end of line character sequence.
Definition: maxtextfile.h:341

When you need to read and write date and time values in a local independent way, use class MaxLocaleHandler.

Returns
A cached C-numeric locale

◆ GetUserLocale()

UtilExport const _locale_t& GetUserLocale ( )

Returns the user locale cached at the start of 3ds Max.

This method should be used when displaying data whose representation is dependent on regional settings in the user interface. For example, when displaying floating point numbers in the UI while the current regional settings are French, the user expects the decimal separator to be ','.

..

// Rendering a floating point value into a string buffer that will be displayed in the UI
TSTR buf;
buf.printf_l(_T("%5.2f\n"), GetUserLocale(), 100.321); // should write 100,321 when the current locale settings are using "," as decimal separator
..
UtilExport const _locale_t & GetUserLocale()
Returns the user locale cached at the start of 3ds Max.
#define TSTR
Definition: strclass.h:1054

When you need to read and write date and time values in a local independent way, use class MaxLocaleHandler, or GetCNumericLocale().

Returns
The cached user locale