Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Objective Grid User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

5.14 Number Formatting

5.14.1 Value Types

CGXStyle::SetValueType() allows you to specify the value type in a cell. Possible types are:

CGXStyle::GetValueType() returns the value type of the cell.

SetValueType() does not affect the way values are stored in CGXStyle. All values are stored as a string. SetValueType() only offers additional information about the value that is stored in the cell. For example, when you apply numeric formatting to a cell, it will only affect the cell if its value type is GX_VT_NUMERIC.

The value type information is very important when you pass style objects to the formula engine. The formula engine parses values to determine if they should be stored as strings or as numbers. It is very important for the formula engine to distinguish between numbers and strings.

5.14.2 Formatting Number Values for Static Cells

The following methods pertain to number formatting:

These methods let you format number values for static cells and specify the precision of the value (the number of significant digits).

Objective Grid lets you format number values for inactive cells and specify the precision when appropriate. The formatted value is only displayed for static (inactive) cells. If you start editing a cell, the original value is displayed.

For example, if you store the value 122.2345 in a cell and then set the format to be fixed with two decimals, 122.23 is displayed in the cell. When you click the cell make the cell active, the cell value changes to 122.2345. Once you leave the cell the cell is made inactive again, the display text reverts to 122.23.

When you apply numeric formatting to a cell, it only affects the cell if the value type is GX_VT_NUMERIC.

Objective Grid supports the following formats. For certain format types you can also specify the number of places (referred to as 'N' in Table 8).

Table 8: Format Types

Format ID Description Definition
GX_FMT_FLOAT Scientific Displays the number in scientific notation (exponent form) with N significant digits.
GX_FMT_FIXED Fixed Displays the number using a fixed number of decimal places, specified by N.
GX_FMT_FIXED_PARENS Fixed Displays the number using a fixed number of decimal places, specified by N. Uses parentheses to indicate negative numbers.
GX_FMT_NUMLOCALE Locale Displays number using locale from regional settings ( , instead of . for example).
GX_FMT_GEN General Displays the number in fixed format or scientific notation, whichever fits. Trailing zeros are not displayed.
GX_FMT_DOLLARS Dollars Displays the number with a leading dollar sign ($) and with comma delimiters, as in $1,000,000. Negative values are displayed in parentheses.
GX_FMT_COMMA Comma Displays the number with comma delimiters, as in 1,000,000. Negative values are displayed in parentheses.
GX_FMT_HEX Hex Display the number in hexadecimal notation. For example, the value 31 is displayed as 1F.
GX_FMT_LOGIC Logic Displays the value 0 as 0, the value 1 as 1, and all other values as ?.
GX_FMT_DAY_MONTH_YEAR DD-MMM-YY Displays the integer portion of a date/time value as a Gregorian date, in the format 01-Aug-99.
GX_FMT_DAY_MONTH DD-MMM Displays the integer portion of a date/time value in the format 01-Aug.
GX_FMT_MONTH_YEAR MMM-YY Displays the integer portion of a date/time value in the format Aug-99.
GX_FMT_DATE MM/DD/YY Displays the integer portion of a date/time value in the format 08/01/99.
GX_FMT_HIDDEN Hidden The cell contents are not displayed.
GX_FMT_TIME HH:MM:SS Displays the fractional portion of a date/time value in the format 06:15:30.
GX_FMT_PERCENT Percent Displays the number as a percentage, multiplying it by 100. For example, the value 0.1 is displayed as 10.00%.
GX_FMT_TEXT Text For cells that contain formulas, the formula itself is displayed rather than the computed value of the cell.
GX_FMT_INTL_DATE DD.MM.YYYY Displays the integer portion of a date/time value in the format 01.08.1999.
GX_FMT_ISO8061_DATE YYYY-MM-DD Displays the integer portion of a date/time value in the ISO 8061 date format 1999-08-01.
GX_FMT_DATETIME MM/DD/YY HH:MM Displays the date and time according to the system settings.
GX_FMT_USER1 User1 If you override GXFormatText you might use these format codes:
GX_FMT_USER2 User2 (GX_FMT_USER1, GX_FMT_USER2
GX_FMT_USER3 User3 GX_FMT_USER3, GX_FMT_USER4)
GX_FMT_USER4 User4 for your own currency formatting (e.g. DM, Lira, ...).

Use CGXStyle::SetFormat() to apply number formatting to cells.

5.14.3 Recognizing Locale Settings in Static Formatting


This applies only to non formula grids.

By default, Objective Grid does not use regional settings when you choose to format numbers. So, it cannot understand that 1.345,13 is a number, and format it properly, even if your system's regional settings are set so that period is the thousands separator and comma is the decimal separator. To get Objective Grid to use your regional settings, add a call to CGXGridCore:: EnableLocaleNumbers() in your grid's Initialize() or OnInitialUpdate() call. After that, any cell using a CGXEditControl that has been formatted using one of the codes listed below will use the numeric locale settings. In addition, with this setting enabled, Objective Grid will recognize values typed into numeric formatted cells as being numerical values.

No matter what the locale settings, the actual numerical values stored in the grid's data object use a period as the decimal separator and do not contain any thousands separator. This convention makes the grid's serialization locale independent. Numbers serialized from a grid using Italian settings can be read into a grid using English settings without losing the numerical values.

Also, for historical reasons, Objective Grid catches system changes through handling the WM_WININICHANGE message. If your code implements a handler for the newer WM_SETTINGCHANGE message, make sure you return a FALSE in your message handler so the grid's handler will also be called.

To customize this behavior, derive your control from CGXEditControl and override one of these three virtual CGXEditControl methods.

By default in a non-formula grid, the code below will display 1234.5555 as 1,234.56 no matter what your regional settings are. But if you add a call to EnableLocaleNumbers() in your initialization code, the formatting will reflect your regional settings. For example, using Italian locale settings would display the value 1234.5555 as 1.234,56.



Previous fileTop of DocumentContentsNo linkNext file

Copyright © Rogue Wave Software, Inc. All Rights Reserved.

The Rogue Wave name and logo, and Stingray, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.