]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/javascript/yui3/build/datatype/datatype-number.js
Release 6.2.2
[Github/sugarcrm.git] / include / javascript / yui3 / build / datatype / datatype-number.js
1 /*
2  Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3  Code licensed under the BSD License:
4  http://developer.yahoo.com/yui/license.html
5  version: 3.3.0
6  build: 3167
7  */
8 YUI.add('datatype-number-parse',function(Y){var LANG=Y.Lang;Y.mix(Y.namespace("DataType.Number"),{parse:function(data){var number=(data===null)?data:+data;if(LANG.isNumber(number)){return number;}
9 else{return null;}}});Y.namespace("Parsers").number=Y.DataType.Number.parse;},'3.3.0',{requires:['yui-base']});YUI.add('datatype-number-format',function(Y){var LANG=Y.Lang;Y.mix(Y.namespace("DataType.Number"),{format:function(data,config){if(LANG.isNumber(data)){config=config||{};var isNeg=(data<0),output=data+"",decPlaces=config.decimalPlaces,decSep=config.decimalSeparator||".",thouSep=config.thousandsSeparator,decIndex,newOutput,count,i;if(LANG.isNumber(decPlaces)&&(decPlaces>=0)&&(decPlaces<=20)){output=data.toFixed(decPlaces);}
10 if(decSep!=="."){output=output.replace(".",decSep);}
11 if(thouSep){decIndex=output.lastIndexOf(decSep);decIndex=(decIndex>-1)?decIndex:output.length;newOutput=output.substring(decIndex);for(count=0,i=decIndex;i>0;i--){if((count%3===0)&&(i!==decIndex)&&(!isNeg||(i>1))){newOutput=thouSep+newOutput;}
12 newOutput=output.charAt(i-1)+newOutput;count++;}
13 output=newOutput;}
14 output=(config.prefix)?config.prefix+output:output;output=(config.suffix)?output+config.suffix:output;return output;}
15 else{return(LANG.isValue(data)&&data.toString)?data.toString():"";}}});},'3.3.0',{requires:['yui-base']});YUI.add('datatype-number',function(Y){},'3.3.0',{use:['datatype-number-parse','datatype-number-format']});