Localization: 4.1 International Formats: Number and Measure

Up: GEOS SDK TechDocs | Up | Prev: 4 International Formats | Next: 4.2 Currency
LocalGetNumericFormat(), LocalSetNumericFormat()
LocalGetMeasurementType(), LocalSetMeasurementType(), LocalAsciiToFixed(), LocalFixedToAscii(), LocalDistanceToAscii(), LocalDistanceFromAscii()

In the USA, 3.142 is a little more than three. In some other countries, it's a little over three thousand. This discrepancy arises from the fact that the decimal and thousands separators are interchanged--in some countries the "." symbol takes the place of the "," symbol when expressing numbers. To allow for local number formats, GEOS provides functions for retrieving and setting the user's preferences.

The number format includes the thousands separator, decimal separator, list separator, and number of decimal digits, as shown in the figure below. The number format also contains a record, NumberFormatFlags , which holds one flag, NFF_LEADING_ZERO . This flag is on if the user wants a leading zero.

There is no overall automatic formatting command for numbers. GEOS supports many internal numeric formats such as fixed point and floating point. If the corresponding math library doesn't contain a formatting command for the number format you're using, you will need to work directly with the localization functions.

The LocalGetNumericFormat() routine returns the numeric format so you may use it to do your own formatting. LocalSetNumericFormat() allows you to reset the user's preferences, though this is inadvisable as it overrides and erases the user's original settings.

These routines use the LocalNumericFormat structure to store the number format data.

The LocalGetMeasurementType() and LocalSetMeasurementType() routines work with the enumerated type MeasurementType , of which there are two: MEASURE_US and MEASURE_METRIC. LocalGetMeasurementType() retrieves the user's current preferred measurement type; LocalSetMeasurementType() sets the user's preference to the passed value. As with any command that resets the user's preference, LocalSetMeasurementType() should never be used by most geodes.

The LocalAsciiToFixed() routine converts an ascii string (e.g. "12.7") to a fixed point number. LocalFixedToAscii() performs the reverse.

To convert between a string like "72 pt" and a number representing a distance, use the LocalDistanceFromAscii() routine. LocalDistanceToAscii() goes the other way, constructing the string corresponding to a given distance. These routines use the DistanceUnit enumerated type to specify the measurement units which are used as shown in the table below.

When allocating strings to use as the targets for Local...ToAscii() routines, allocating a buffer of size LOCAL_DISTANCE_BUFFER_SIZE will be sufficient.

Table 8-1 DistanceUnit types

DistanceUnit value # of Points Display Format Entry Format(s)

DU_POINTS 1.000 ###.### pt ###.### pt

DU_INCHES 72.000 ###.### in ###.### in ###.###"

DU_CENTIMETERS 28.346 ###.### cm ###.###cm

DU_MILLIMETERS 2.835 ###.### mm ###.###mm

DU_PICAS 12.000 ###.### pi ###.### pi

DU_EUR_POINTS 1.065 ###.### ep ###.### ep

DU_CICEROS 12.787 ###,### ci ###.### ci

DU_POINTS_OR_MILLIMETERS and DU_INCHES_OR_CENTIMETERS: special cases


Up: GEOS SDK TechDocs | Up | Prev: 4 International Formats | Next: 4.2 Currency