08.01.2015 Views

Beginning Web Development, Silverlight, and ASP.NET AJAX

Beginning Web Development, Silverlight, and ASP.NET AJAX

Beginning Web Development, Silverlight, and ASP.NET AJAX

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

350<br />

CHAPTER 14 ■ JAVASCRIPT PROGRAMMING WITH <strong>ASP</strong>.<strong>NET</strong> <strong>AJAX</strong><br />

Error.notImplemented: This allows you to create an error that declares that the desired<br />

piece of functionality has not been implemented.<br />

Error.parameterCount: This allows you to create an error that defines that the parameter<br />

set passed to the function is incorrect.<br />

Number Type Extensions<br />

These extend the base JavaScript Number object with some new static <strong>and</strong> instance<br />

methods.<br />

Formatting a Number<br />

You can format a number using the format function. This uses a culture-independent<br />

value, based on the en-US culture. For example, if you want to format a number as a currency<br />

(c format), you can use the following:<br />

var a = 20;<br />

var v = a.format("c");<br />

To use the current culture to format the number, you can use the localeFormat function.<br />

This formats the number based on the current system locale. To underst<strong>and</strong> how to<br />

configure this, you should check out the <strong>ASP</strong>.<strong>NET</strong> documentation on globalization <strong>and</strong><br />

localization. The script to format the number according to the current culture is identical:<br />

var a = 20;<br />

var v = a.localeFormat("c");<br />

Parsing a Number<br />

You can create a new number var by parsing a string value. This is a static function <strong>and</strong><br />

can be called without creating an instance of the object:<br />

var n = Number.parseInvariant("23.2");<br />

Additionally, you can parse a localized string to get a number using the parseLocale<br />

function, like this:<br />

var n = Number.parseLocale("23,2");

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!