Matt Snider![]()
This Y augmentation will add the Number namespace to the Y instance. This namespace will contain at least the following methods:
Format is probably the most powerful method, simplifying the conversion of numbers to string formats. Although I find myself using the isBetween/isNotBetween functions and the isEven/isOdd methods fairly regularly.
For a complete writeup, see the <a href="http://www.mattsnider.com/javascript/yui-3-number-gallery-component/">YUI 3 Number Gallery Component</a> article on my blog.
Here is an example showing several ways to format numbers using the Y.Number.format method.
<script src="http://yui.yahooapis.com/3.0.0/build/yui/yui-min.js"></script>YUI({
//Last Gallery Build of this module
gallery: 'gallery-2010.03.10-18'
}).use('gallery-number', function(Y) {
Y.Number.format(1000); // will be "1,000.00"
Y.Number.format(1000, '0,0'); // will be "1,000"
Y.Number.format(1000000, "0") // will be "1000000"
Y.Number.format(1000000, "$0,0") // will be "$1,000,000"
});| Subject | Author | Date |
|---|---|---|
| Number module writeup on YUIBlog | Eric Miraglia | 03/11/10 |
| Does not work in 3.5.1 or 3.6.0pr1 | John Mizliso | 05/31/12 |
| Re: Does not work in 3.5.1 or 3.6.0pr1 | Allen Rabinovich | 05/31/12 |
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info