YUILibrary - Open source JavaScript and CSS for building richly interactive software.
Fork YUI on GitHub
  • Home
  • Gallery
  • Forums
  • YUI 2
  • YUI 3
  • YUI Compressor
  • YUI Doc
  • More
  • Gallery Forums
  • Gallery Stats
  • Gallery Calendar
  • Register
  • Login

Modules

  • Home
  • Featured
  • Popular
  • New
  • All

Documentation

  • FAQ
  • Developer FAQ
  • Developer Guide
  • Module Setup

Tag Cloud

jafl filter caridy lsmith overlay rgrove skinnable widget form event port slideshow adam jsonp nzakas html5 animation apipkin ajax foxxtrot davglass io yui2 node plugin ericf

Context Navigation

    YUI Library is not responsible for bugs or support with this module. It is available as a free service. For support please contact the module owner with the provided links.

    Number (gallery-number) on cdn

    Last Updated: 03/8/10
    + 1 -

    Matt Snider

    YUI Contributor

    See 1 more by this user.

    Created: 10/30/09
    Last CDN Push: 03/10/10
    Build Tag: gallery-2010.03.10-18
    Project: YUI 3
    License: YUI BSD
    YUI Version: 3.0.0
    Free for use.

    This Y augmentation will add the Number namespace to the Y instance. This namespace will contain at least the following methods:

    • degrees(Number) // converts radians to degrees
    • format(Number, String) // formats a number into a string
    • getPrecision(Number) // determines decimal places
    • isBetween(Number, Number, Number, Boolean)
    • isEven(Number)
    • isNotBetween(Number, Number, Number, Boolean)
    • isOdd
    • isPrime
    • radians(Number) // converts degrees to radians
    • random(Number, Number)
    • roundToDigit(Number, Number) // rounds to the nearest digit

    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.

    • Tags:
    • matt.snider
    • Download
    • Docs
    • Homepage
    • Bugs
    • Source
    • Example
    • Forum
    • History

    Here is an example showing several ways to format numbers using the Y.Number.format method.

    Code Sample

    <script src="http://yui.yahooapis.com/3.1.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"
    });

    Forum Posts

    Subject Author Date
    Number module writeup on YUIBlog Eric Miraglia 03/11/10
    YUI Projects
    • All YUI Downloads
    • YUI 2
    • YUI 3
    • YUI Doc
    • YUI Compressor
    • YUILibrary.com
    • YUI Build Tool
    • YUI PHP Loader
    Pages & Links
    • All YUI Downloads
    • Git FAQ
    • Graded Browser Support
    • Contribute to YUI
    • Forum Stats
    • Gallery Stats
    • YUI Calendar
    Contribute
    • Submit a Bug
    • Request a Feature
    • Write Code
    • Meet the Team
    Follow YUI
    • on GitHub
    • on Twitter
    • on FriendFeed
    • on Facebook
    • on IRC
    • YUI Blog
    • YUI Theater
    • YUI Forums

    © 2010 YUI Library - Site Credits