• Register
  • Log In
  • Home
  • Quick Start
    • Configurator
    • Download YUI 3
  • Documentation
    • User Guides
    • Examples
    • Tutorials
    • API Docs
  • Community
    • Gallery
    • Blog »
    • Forums
    • YUI Theater
    • Calendar
  • Contribute
    • YUI on GitHub »
    • File a Ticket
    • View Tickets
    • Dashboard
  • Other Projects
    • YUI 2
    • YUI Compressor
    • YUI Doc »
    • YUI Builder
    • YUI PHP Loader
    • YUI Test
    • YUI Website
  • YUI
  • >
  • Community
  • >
  • Gallery

Gallery

Modules

  • Home
  • Featured
  • Popular
  • New
  • All

Documentation

  • FAQ
  • Developer FAQ
  • Developer Guide
  • Module Setup

Tag Cloud

lsmith jafl css nzakas event yql solmsted satyam node caridy plugin datatable table async foxxtrot greghinch model ericf liferay form apipkin io widget davglass animation

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 2 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.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"
    });

    Forum Posts

    Subject Author Date
    Number module writeup on YUIBlog Eric Miraglia 03/11/10

    © 2006-2011 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