# Yahoo! UI Library

### datatype 3.0.0b1

Yahoo! UI Library > datatype > datatype-number-parse.js (source view)
Search:
Filters
Show Private Show Protected Show Deprecated

    /**
     * Parse number submodule.
     *
     * @module datatype
     * @submodule datatype-number-parse
     * @for DataType.Number
     */

    var LANG = Y.Lang;

    Y.mix(Y.namespace("DataType.Number"), {
        /**
         * Converts data to type Number.
         *
         * @method parse
         * @param data {String | Number | Boolean} Data to convert. The following
         * values return as null: null, undefined, NaN, "".
         * @return {Number} A number, or null.
         */
        parse: function(data) {
            var number = (data === null) ? data : +data;
            if(LANG.isNumber(number)) {
                return number;
            }
            else {
                Y.log("Could not parse data " + Y.dump(data) + " to type Number", "warn", "datatype-number");
                return null;
            }
        }
    });

    // Add Parsers shortcut
    Y.namespace("Parsers").number = Y.DataType.Number.parse;

Copyright © 2009 Yahoo! Inc. All rights reserved.