SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 109 | Next

Robin Pars, Laurence Moroney, and John Grieb

"Foundations of ASP.NET AJAX"

g., percentage, currency, etc.). These
format providers are listed in Table 4-6.
Table 4-6. List of the Supported Number Formats
Format Description
p The number is converted to a string that represents a percent (e.g., -
1,234.56 %).
d The number is converted to a string of decimal digits (0-9), prefixed by
a minus sign if the number is negative (e.g., -1234.56).
c The number is converted to a string that represents a currency amount
(e.g., $1,234.56).
n The number is converted to a string of the form "-d,ddd,ddd.ddd??¦"
(e.g., -1,234.56).
So as you can see the c format provider can be used to automatically format a number
into currency and even localize as specified by the CultureInfo class on the server.
The following script uses the parseInvariant method to parse out a number from a string
value, and then using the localeFormat, the number is displayed as a currency value.
function DisplayCurrency() {
var num = Number.parseInvariant("130.52");
alert (num.localeFormat("c"));
}
And, because the current culture had been implicitly set to United States, the currency
format is $ with cents displayed after the decimal place as shown in Figure 4-4.


Pages:
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121