beautypg.com

A note on setting environment variables – HP Integrity NonStop J-Series User Manual

Page 244

background image

balance of $10.00 in the United States, you could say:

double sawbuck = 1000.;

This representation has the advantages of wide range, exactness, and portability. Wide range means
you can exactly represent values from $0.00 up to and beyond $10,000,000,000,000.00 - larger than
any likely budget. Exactness means that, representing monetary values without fractional parts, you
can perform arithmetic on them and compare the results for equality:

double price = 999.; // $9.99
double penny = 1.; // $.01
assert(price + penny == sawbuck);

This would not be possible if the values were naively represented, as in price = 9.99;.

Portability means simply that double is a standard type, unlike common 64-bit integer or BCD
representations. Of course, you can perform financial calculations on such other representations, but
because you can always convert between them and double, they are all supported. In the future,

RWLocale

may directly support some other common representations as well.

Consider the following examples of currency conversions:

const RWLocale& here = RWLocale::global();
double sawbuck = 1000.;
RWCString tenNone = here.moneyAsString(sawbuck, RWLocale::NONE);
RWCString tenLocal = here.moneyAsString(sawbuck,RWLocale::LOCAL);
RWCString tenIntl = here.moneyAsString(sawbuck, RWLocale::INTL);
if (here.stringToMoney(tenNone, &sawbuck) &&
here.stringToMoney(tenLocal, &sawbuck) &&
here.stringToMoney(tenIntl, &sawbuck)) // verify conversion
cout << sawbuck << " " << tenNone << " "
<< tenLocal << " " << tenIntl << " " << endl;

In a United States locale, the code would display as:

1000.00000 10.00 $10.00 USD 10.00

A Note on Setting Environment Variables

As mentioned in the section on class

RWTime

, some compilers and operating systems, including the

Windows operating systems, require you to set certain environment variables in order for a locale
feature to work. Failure to do this can lead to great difficulties.

If you use Borland, MetaWare, Microsoft, Symantec, or Watcom, you must set your environment
variable TZ to the appropriate time zone:

set TZ=PST8PDT

Check the documentation for your compiler and operating system for information on setting
environment variables.

This manual is related to the following products: