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
parseNumber ([Locale lc,] String value[, int type]) yoix.util
parseNumber ([Locale lc,] String value[, Dictionary attributes])  
 
converts the given String value, into either an int or double value, as appropriate and as 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 parsing by use of the following dictionary entries:
decimalSeparatorAlwaysShown While it is not an error to include this value, it really only has meaning when used for number formatting. See numberFormat. Not for use with INTEGER_TYPE.
groupingSize While it is not an error to include this value, it really only has meaning when used for number formatting. See numberFormat. Not for use with INTEGER_TYPE.
groupingUsed When non-zero, this int value indicates that grouping may be present in the value to be parsed. A zero value will cause parsing to stop when a grouping separator is encountered.
maximumFractionDigits While it is not an error to include this value, it really only has meaning when used for number formatting. See numberFormat.
maximumIntegerDigits While it is not an error to include this value, it really only has meaning when used for number formatting. See numberFormat.
minimumFractionDigits While it is not an error to include this value, it really only has meaning when used for number formatting. See numberFormat.
minimumIntegerDigits While it is not an error to include this value, it really only has meaning when used for number formatting. See numberFormat.
multiplier An int value that sets the multiplier used for percent or similar values. In other words, with a multiplier of 100, a 10% value would be parsed as 0.1. Not for use with INTEGER_TYPE.
negativePrefix A String, used in conjunction with negativeSuffix, that will cause a number to be parsed as a negative value. 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, used in conjunction with negativePrefix, that will cause a number to be parsed as a negative value. 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.
positivePrefix A String, used in conjunction with positiveSuffix, that will cause a number to be parsed as a positive value. Not for use with INTEGER_TYPE.
positiveSuffix A String, used in conjunction with positivePrefix, that will cause a number to be parsed as a positive value. 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 parsing 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.*;

stdout.nextline = toString(parseNumber("1234"));
stdout.nextline = toString(parseNumber("1234.5678"));
stdout.nextline = toString(parseNumber("1234", INTEGER_TYPE));
stdout.nextline = toString(parseNumber("1234.5678", INTEGER_TYPE));
stdout.nextline = toString(parseNumber("$1234", MONEY_TYPE));
stdout.nextline = toString(parseNumber("$1234.5678", MONEY_TYPE));
stdout.nextline = toString(parseNumber("$1,234", MONEY_TYPE));
stdout.nextline = toString(parseNumber("$1,234.56", MONEY_TYPE));
stdout.nextline = toString(parseNumber("($1,234.56)", MONEY_TYPE));
stdout.nextline = toString(parseNumber("1,234%", PERCENT_TYPE));
stdout.nextline = toString(parseNumber("1,234.5678%", PERCENT_TYPE));
stdout.nextline = toString(parseNumber("1,234%", new Dictionary {
    int type = PERCENT_TYPE;
    int multiplier = 10000;
}));
stdout.nextline = toString(parseNumber("1,234.5678%", new Dictionary {
    int type = PERCENT_TYPE;
    int multiplier = 10000;
}));
yields the following results on standard output:
1234
1234.5678
1234
1234
1234
1234.5678
1234
1234.56
-1234.56
12.34
12.345678
0.1234
0.12345678
 
 Return:   Number
 
 See Also:   Locale, numberFormat, parseDate, parseTimer

 

Yoix is a registered trademark of AT&T Inc.