AT&T Home | AT&T Labs | Research
AT&T Labs, Inc. - Research

The Yoix® Scripting Language

Home | What's New | Grammar | Documentation | Download | License | YChart | YDAT | YWAIT | Byzgraf | FAQs
numberFormat ([Locale lc,] Number value[, int type]) yoix.util
numberFormat ([Locale lc,] Number value[, Dictionary attributes])  
 
formats the given numeric value, either integer or floating-point, in the format suitable for the user's default locale or as provided by lc. When provided, type can be one of: DOUBLE_TYPE, INTEGER_TYPE, MONEY_TYPE or PERCENT_TYPE. The default is DOUBLE_TYPE. When provided, attributes can fine-tune the formatting by use of the following dictionary entries:
decimalSeparatorAlwaysShown When non-zero, this int value indicates that the decimal separator, e.g., the decimal point in the US, will always be present even if the supplied number is an integer. When zero, the separator appears as needed. Not for use with INTEGER_TYPE.
groupingSize An int providing the number of digits grouped together when the number is large. In the US, for example, the grouping would be by commas every three digits. Not for use with INTEGER_TYPE.
groupingUsed When non-zero, this int value indicates that grouping should be used. A zero value turns off grouping.
maximumFractionDigits An int indicating the maximum number of fraction digits to be displayed. In the US, this means the maximum number of digits to the right of the decimal point.
maximumIntegerDigits An int indicating the maximum number of whole digits to be displayed. In the US, this means the maximum number of digits to the left of the decimal point.
minimumFractionDigits An int indicating the minimum number of fraction digits to be displayed. In the US, this means the minimum number of digits to the right of the decimal point.
minimumIntegerDigits An int indicating the minimum number of whole digits to be displayed. In the US, this means the minimum number of digits to the left of the decimal point.
multiplier An int value that sets the multiplier for use in percent or similar values. In other words, with a multiplier of 100, a 0.1 value would be formatted as 10%. Not for use with INTEGER_TYPE.
negativePrefix A String value that will be placed before the (integer) digits of a negative number. In the US, this would normally be a minus sign, but for financial values it would be a left parenthesis. Not for use with INTEGER_TYPE.
negativeSuffix A String value that will be placed after the (fractional) digits of a negative number. In the US, this would normally be an empty string, but for financial values it would be a right parenthesis. Not for use with INTEGER_TYPE.
parseIntegerOnly A non-zero int value indicates that only the integer portion of a number should be parsed. While it is not an error to include this value, it really only has meaning when used for number parsing. See parseNumber.
positivePrefix A String value that will be placed before the (integer) digits of a positive number. Not for use with INTEGER_TYPE.
positiveSuffix A String value that will be placed after the (fractional) digits of a positive number. Not for use with INTEGER_TYPE.
type An int value that is one of DOUBLE_TYPE, INTEGER_TYPE, MONEY_TYPE or PERCENT_TYPE and is used to determine which formatting category should be applied to the given value. The default is DOUBLE_TYPE.
 
 Example:   The following example, when run in the US locale:
import yoix.util.*;

int inbr = 12345678;
double dnbr = 123456.7890;

stdout.nextline = "Test 1 =============";
stdout.nextline = numberFormat(inbr);
stdout.nextline = numberFormat(dnbr);
stdout.nextline = numberFormat(inbr, DOUBLE_TYPE);
stdout.nextline = numberFormat(dnbr, DOUBLE_TYPE);
stdout.nextline = numberFormat(inbr, INTEGER_TYPE);
stdout.nextline = numberFormat(dnbr, INTEGER_TYPE);
stdout.nextline = numberFormat(inbr, MONEY_TYPE);
stdout.nextline = numberFormat(dnbr, MONEY_TYPE);
stdout.nextline = numberFormat(inbr, PERCENT_TYPE);
stdout.nextline = numberFormat(dnbr, PERCENT_TYPE);
yields the following results on standard output:
Test 1 =============
12,345,678
123,456.789
12,345,678
123,456.789
12,345,678
123,457
$12,345,678.00
$123,456.79
1,234,567,800%
12,345,679%
 
 Return:   String
 
 See Also:   date, Locale, parseNumber, timerFormat

 

Yoix is a registered trademark of AT&T Inc.