From keld Mon Apr 13 21:57:45 1998 Received: (from keld@localhost) by dkuug.dk (8.6.12/8.6.12) id VAA10859 for sc22wg15; Mon, 13 Apr 1998 21:57:45 +0200 Message-Id: <199804131957.VAA10859@dkuug.dk> From: keld@dkuug.dk (Keld J|rn Simonsen) Date: Mon, 13 Apr 1998 21:57:45 +0200 X-Charset: ISO-8859-1 X-Char-Esc: 29 Mime-Version: 1.0 Content-Type: Text/Plain; Charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Mnemonic-Intro: 29 X-Mailer: Mail User's Shell (7.2.2 4/12/91) To: sc22wg15 Subject: API for monetary formatting, covering Euro This is in reponse to the action item on covering the Euro. money2string Rationale: The money2string function needs to have a number of capabilities: 1. functionality of X/Open and C++: strfmon and money_put 2. exact mode - integer 64 bits 3. handle euro in transparant way 4. threads-safe - needs locale parameter 5. programming language independent - with C and C++ bindings 6. Interfaces to data specified with ISO 14652. Point 3 needs further elaboration. In countries with the Euro it is required by law in a period of 2 1/2 years to display both the national currency and the euro. The program should be the same whether it is intended say for USA or Denmark that do not have the Euro, or France and Germany which has the euro. Also there should not be a need to change locales when a country shifts from national currency to the dual currency, nor when the country changes to just Euro. Example of use (in C): modifylocale(LC_ALL,"de_DE",lc); money2string(s,"%i%d %i",123456,19990601,lc); may format "s" to contain "DEM 1.234,56 EUR 433,84" modifylocale(LC_ALL,"en_US",lc); money2string(s,"%i%d %i",123456,19990601,lc); may format "s" to contain "USD 1,234.56" Specification The following is using ISO 15435 notation. 9.9 procedure money2string(out s:string; in f: string; in a: money; in t: time; in lc: locale) returns integer; Procedure "moneystring" returns in parameter "s" a string formatted according to the format "f" of the money value "a". The formatting is done with respect to the locale "lc" at the time given in "t". The return value is the number of characters formatted, or -1 if an error occurred. The parameter "f" is a string that consist of characters that shall be transfered to the output string "s" literally, and formatting specifications that specifies how the money value "a" is to be formatted. A formatting specification consist of the following sequence: - a "%" character - optional flags - optional field width - optional left precision - optional right position - the formatting character to specify which formatting to perform. Flags are given with special characters, width and precision information is given with decimal digits, and formating characters are given with latin letters or the character "%". The flags are: "=f" an "=" followed by a single character which is used as the numeric fill character. No restriction is made on the representation of this single character. The default numeric fill character is the SPACE character. This flag does not affect the field width filling which always uses the SPACE character. This flag is ignored unless a left precision (se below) is specified. "^" Do not use the grouping characters when formatting the amount. The default is to insert the grouping characters if defined in the locale "lc". "+" or "(" Specify the style of representing positive and negative amounts. Only one of "+" or "(" may be specified. If "+" is specified, the equivalent of "+" and "-" are used from the locale "lc". If "(" is specified, negative amounts are enclosed within parenthesis. If neither flag is specified, the "+" style is used. "!" Suppersses the currency symbol from the output conversion. "-" Specify the alignment. If this flag is present all fields are left-justified (padded to the right) rather than right-justified. Field Width w A string of decimal digits specifying the minimum field width in characters in which the result of the conversion is right-justified (or left-justified if the "-" flag is specified) The default is 0. Left Precision "#n" A "#" followed by a string of decimal digits specifying a maximum number of digits expected to be formatted to the left of the radix character. This option can be used to keep the formatted output from several calls to procedure "money2string" aligned in the same coloumns. It can also be used to fill unused positions with a special character specified with the "=f" flag, as in $***123.45. If more than "n" positions are required, this formatting specification is ignored. Digit positions in excess of those actually required are filled with the numeric fill character, see the "=f" flag above. If grouping has not been suppressed with the "^" flag, and it is defined for the locale "lc", grouping separators are inserted before the fill characters (if any) are added. Grouping separators are not applied to fill characters, even if the fill character is a digit. To ensure alignment, any characters appearing before or after the number in the formatted output such as currency or sign, symbols are padded as neccessary with SPACE characters to make their positive or negative formats an equal length. Right precision ".p" A "." followed by a string of decimal digits specifying the number after the radix character. If the value of the right precision is 0, no radix character appears. If a right precision is not included, the value specified in the "lc" locale is used. It is recommended to normally use the value from the locale. The amount being formatted is rounded to the specified number of digits prior to formatting. Formatting characters The formatting characters and their meanings are: "d" The following characters and up to any corresponding "%d" or the end of the formatting string are only interpreted if there is a second currency in the "lc" locale for the time "t". The amount "a" is converted according to the "conversion_rate" of the locale "lc" and formatted according to any following formatting characters. No argument is converted. There shall be no flags, nor width or precision parameters, just "%%" is allowed. "i" The type money argument is formatted acording to the "lc" locales's international currency format. "n" The type money argument is formatted acording to the "lc" locales's national currency format. "%" Convert to a "%"; no argument is converted. There shall be no flags, nor width or precision parameters, just "%%" is allowed. The C binding is: 9.9 int money2string(string s, string f, money a, time t, locale lc);