+<!DOCTYPE html>
<html>
<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The source code</title>
- <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
- <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
+ <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
+ <script type="text/javascript" src="../prettify/prettify.js"></script>
+ <style type="text/css">
+ .highlight { display: block; background-color: #ddd; }
+ </style>
+ <script type="text/javascript">
+ function highlight() {
+ document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
+ }
+ </script>
</head>
-<body onload="prettyPrint();">
- <pre class="prettyprint lang-js">/*!
- * Ext JS Library 3.0.3
- * Copyright(c) 2006-2009 Ext JS, LLC
- * licensing@extjs.com
- * http://www.extjs.com/license
+<body onload="prettyPrint(); highlight();">
+ <pre class="prettyprint lang-js"><span id='Ext-util-Format'>/**
+</span> * @class Ext.util.Format
+
+This class is a centralized place for formatting functions inside the library. It includes
+functions to format various different types of data, such as text, dates and numeric values.
+
+__Localization__
+This class contains several options for localization. These can be set once the library has loaded,
+all calls to the functions from that point will use the locale settings that were specified.
+Options include:
+- thousandSeparator
+- decimalSeparator
+- currenyPrecision
+- currencySign
+- currencyAtEnd
+This class also uses the default date format defined here: {@link Ext.date#defaultFormat}.
+
+__Using with renderers__
+There are two helper functions that return a new function that can be used in conjunction with
+grid renderers:
+
+ columns: [{
+ dataIndex: 'date',
+ renderer: Ext.util.Format.dateRenderer('Y-m-d')
+ }, {
+ dataIndex: 'time',
+ renderer: Ext.util.Format.numberRenderer('0.000')
+ }]
+
+Functions that only take a single argument can also be passed directly:
+ columns: [{
+ dataIndex: 'cost',
+ renderer: Ext.util.Format.usMoney
+ }, {
+ dataIndex: 'productCode',
+ renderer: Ext.util.Format.uppercase
+ }]
+
+__Using with XTemplates__
+XTemplates can also directly use Ext.util.Format functions:
+
+ new Ext.XTemplate([
+ 'Date: {startDate:date("Y-m-d")}',
+ 'Cost: {cost:usMoney}'
+ ]);
+
+ * @markdown
+ * @singleton
*/
-<div id="cls-Ext.util.Format"></div>/**\r
- * @class Ext.util.Format\r
- * Reusable data formatting functions\r
- * @singleton\r
- */\r
-Ext.util.Format = function(){\r
- var trimRe = /^\s+|\s+$/g;\r
- return {\r
- <div id="method-Ext.util.Format-ellipsis"></div>/**\r
- * Truncate a string and add an ellipsis ('...') to the end if it exceeds the specified length\r
- * @param {String} value The string to truncate\r
- * @param {Number} length The maximum length to allow before truncating\r
- * @param {Boolean} word True to try to find a common work break\r
- * @return {String} The converted text\r
- */\r
- ellipsis : function(value, len, word){\r
- if(value && value.length > len){\r
- if(word){\r
- var vs = value.substr(0, len - 2);\r
- var index = Math.max(vs.lastIndexOf(' '), vs.lastIndexOf('.'), vs.lastIndexOf('!'), vs.lastIndexOf('?'));\r
- if(index == -1 || index < (len - 15)){\r
- return value.substr(0, len - 3) + "...";\r
- }else{\r
- return vs.substr(0, index) + "...";\r
- }\r
- } else{\r
- return value.substr(0, len - 3) + "...";\r
- }\r
- }\r
- return value;\r
- },\r
-\r
- <div id="method-Ext.util.Format-undef"></div>/**\r
- * Checks a reference and converts it to empty string if it is undefined\r
- * @param {Mixed} value Reference to check\r
- * @return {Mixed} Empty string if converted, otherwise the original value\r
- */\r
- undef : function(value){\r
- return value !== undefined ? value : "";\r
- },\r
-\r
- <div id="method-Ext.util.Format-defaultValue"></div>/**\r
- * Checks a reference and converts it to the default value if it's empty\r
- * @param {Mixed} value Reference to check\r
- * @param {String} defaultValue The value to insert of it's undefined (defaults to "")\r
- * @return {String}\r
- */\r
- defaultValue : function(value, defaultValue){\r
- return value !== undefined && value !== '' ? value : defaultValue;\r
- },\r
-\r
- <div id="method-Ext.util.Format-htmlEncode"></div>/**\r
- * Convert certain characters (&, <, >, and ') to their HTML character equivalents for literal display in web pages.\r
- * @param {String} value The string to encode\r
- * @return {String} The encoded text\r
- */\r
- htmlEncode : function(value){\r
- return !value ? value : String(value).replace(/&/g, "&").replace(/>/g, ">").replace(/</g, "<").replace(/"/g, """);\r
- },\r
-\r
- <div id="method-Ext.util.Format-htmlDecode"></div>/**\r
- * Convert certain characters (&, <, >, and ') from their HTML character equivalents.\r
- * @param {String} value The string to decode\r
- * @return {String} The decoded text\r
- */\r
- htmlDecode : function(value){\r
- return !value ? value : String(value).replace(/>/g, ">").replace(/</g, "<").replace(/"/g, '"').replace(/&/g, "&");\r
- },\r
-\r
- <div id="method-Ext.util.Format-trim"></div>/**\r
- * Trims any whitespace from either side of a string\r
- * @param {String} value The text to trim\r
- * @return {String} The trimmed text\r
- */\r
- trim : function(value){\r
- return String(value).replace(trimRe, "");\r
- },\r
-\r
- <div id="method-Ext.util.Format-substr"></div>/**\r
- * Returns a substring from within an original string\r
- * @param {String} value The original text\r
- * @param {Number} start The start index of the substring\r
- * @param {Number} length The length of the substring\r
- * @return {String} The substring\r
- */\r
- substr : function(value, start, length){\r
- return String(value).substr(start, length);\r
- },\r
-\r
- <div id="method-Ext.util.Format-lowercase"></div>/**\r
- * Converts a string to all lower case letters\r
- * @param {String} value The text to convert\r
- * @return {String} The converted text\r
- */\r
- lowercase : function(value){\r
- return String(value).toLowerCase();\r
- },\r
-\r
- <div id="method-Ext.util.Format-uppercase"></div>/**\r
- * Converts a string to all upper case letters\r
- * @param {String} value The text to convert\r
- * @return {String} The converted text\r
- */\r
- uppercase : function(value){\r
- return String(value).toUpperCase();\r
- },\r
-\r
- <div id="method-Ext.util.Format-capitalize"></div>/**\r
- * Converts the first character only of a string to upper case\r
- * @param {String} value The text to convert\r
- * @return {String} The converted text\r
- */\r
- capitalize : function(value){\r
- return !value ? value : value.charAt(0).toUpperCase() + value.substr(1).toLowerCase();\r
- },\r
-\r
- // private\r
- call : function(value, fn){\r
- if(arguments.length > 2){\r
- var args = Array.prototype.slice.call(arguments, 2);\r
- args.unshift(value);\r
- return eval(fn).apply(window, args);\r
- }else{\r
- return eval(fn).call(window, value);\r
- }\r
- },\r
-\r
- <div id="method-Ext.util.Format-usMoney"></div>/**\r
- * Format a number as US currency\r
- * @param {Number/String} value The numeric value to format\r
- * @return {String} The formatted currency string\r
- */\r
- usMoney : function(v){\r
- v = (Math.round((v-0)*100))/100;\r
- v = (v == Math.floor(v)) ? v + ".00" : ((v*10 == Math.floor(v*10)) ? v + "0" : v);\r
- v = String(v);\r
- var ps = v.split('.');\r
- var whole = ps[0];\r
- var sub = ps[1] ? '.'+ ps[1] : '.00';\r
- var r = /(\d+)(\d{3})/;\r
- while (r.test(whole)) {\r
- whole = whole.replace(r, '$1' + ',' + '$2');\r
- }\r
- v = whole + sub;\r
- if(v.charAt(0) == '-'){\r
- return '-$' + v.substr(1);\r
- }\r
- return "$" + v;\r
- },\r
-\r
- <div id="method-Ext.util.Format-date"></div>/**\r
- * Parse a value into a formatted date using the specified format pattern.\r
- * @param {String/Date} value The value to format (Strings must conform to the format expected by the javascript Date object's <a href="http://www.w3schools.com/jsref/jsref_parse.asp">parse()</a> method)\r
- * @param {String} format (optional) Any valid date format string (defaults to 'm/d/Y')\r
- * @return {String} The formatted date string\r
- */\r
- date : function(v, format){\r
- if(!v){\r
- return "";\r
- }\r
- if(!Ext.isDate(v)){\r
- v = new Date(Date.parse(v));\r
- }\r
- return v.dateFormat(format || "m/d/Y");\r
- },\r
-\r
- <div id="method-Ext.util.Format-dateRenderer"></div>/**\r
- * Returns a date rendering function that can be reused to apply a date format multiple times efficiently\r
- * @param {String} format Any valid date format string\r
- * @return {Function} The date formatting function\r
- */\r
- dateRenderer : function(format){\r
- return function(v){\r
- return Ext.util.Format.date(v, format);\r
- };\r
- },\r
-\r
- // private\r
- stripTagsRE : /<\/?[^>]+>/gi,\r
- \r
- <div id="method-Ext.util.Format-stripTags"></div>/**\r
- * Strips all HTML tags\r
- * @param {Mixed} value The text from which to strip tags\r
- * @return {String} The stripped text\r
- */\r
- stripTags : function(v){\r
- return !v ? v : String(v).replace(this.stripTagsRE, "");\r
- },\r
-\r
- stripScriptsRe : /(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)/ig,\r
-\r
- <div id="method-Ext.util.Format-stripScripts"></div>/**\r
- * Strips all script tags\r
- * @param {Mixed} value The text from which to strip script tags\r
- * @return {String} The stripped text\r
- */\r
- stripScripts : function(v){\r
- return !v ? v : String(v).replace(this.stripScriptsRe, "");\r
- },\r
-\r
- <div id="method-Ext.util.Format-fileSize"></div>/**\r
- * Simple format for a file size (xxx bytes, xxx KB, xxx MB)\r
- * @param {Number/String} size The numeric value to format\r
- * @return {String} The formatted file size\r
- */\r
- fileSize : function(size){\r
- if(size < 1024) {\r
- return size + " bytes";\r
- } else if(size < 1048576) {\r
- return (Math.round(((size*10) / 1024))/10) + " KB";\r
- } else {\r
- return (Math.round(((size*10) / 1048576))/10) + " MB";\r
- }\r
- },\r
-\r
- <div id="method-Ext.util.Format-math"></div>/**\r
- * It does simple math for use in a template, for example:<pre><code>\r
- * var tpl = new Ext.Template('{value} * 10 = {value:math("* 10")}');\r
- * </code></pre>\r
- * @return {Function} A function that operates on the passed value.\r
- */\r
- math : function(){\r
- var fns = {};\r
- return function(v, a){\r
- if(!fns[a]){\r
- fns[a] = new Function('v', 'return v ' + a + ';');\r
- }\r
- return fns[a](v);\r
- }\r
- }(),\r
-\r
- <div id="method-Ext.util.Format-round"></div>/**\r
- * Rounds the passed number to the required decimal precision.\r
- * @param {Number/String} value The numeric value to round.\r
- * @param {Number} precision The number of decimal places to which to round the first parameter's value.\r
- * @return {Number} The rounded value.\r
- */\r
- round : function(value, precision) {\r
- var result = Number(value);\r
- if (typeof precision == 'number') {\r
- precision = Math.pow(10, precision);\r
- result = Math.round(value * precision) / precision;\r
- }\r
- return result;\r
- },\r
-\r
- <div id="method-Ext.util.Format-number"></div>/**\r
- * Formats the number according to the format string.\r
- * <div style="margin-left:40px">examples (123456.789):\r
- * <div style="margin-left:10px">\r
- * 0 - (123456) show only digits, no precision<br>\r
- * 0.00 - (123456.78) show only digits, 2 precision<br>\r
- * 0.0000 - (123456.7890) show only digits, 4 precision<br>\r
- * 0,000 - (123,456) show comma and digits, no precision<br>\r
- * 0,000.00 - (123,456.78) show comma and digits, 2 precision<br>\r
- * 0,0.00 - (123,456.78) shortcut method, show comma and digits, 2 precision<br>\r
- * To reverse the grouping (,) and decimal (.) for international numbers, add /i to the end.\r
- * For example: 0.000,00/i\r
- * </div></div>\r
- * @param {Number} v The number to format.\r
- * @param {String} format The way you would like to format this text.\r
- * @return {String} The formatted number.\r
- */\r
- number: function(v, format) {\r
- if(!format){\r
- return v;\r
- }\r
- v = Ext.num(v, NaN);\r
- if (isNaN(v)){\r
- return '';\r
- }\r
- var comma = ',',\r
- dec = '.',\r
- i18n = false,\r
- neg = v < 0;\r
- \r
- v = Math.abs(v);\r
- if(format.substr(format.length - 2) == '/i'){\r
- format = format.substr(0, format.length - 2);\r
- i18n = true;\r
- comma = '.';\r
- dec = ',';\r
- }\r
- \r
- var hasComma = format.indexOf(comma) != -1, \r
- psplit = (i18n ? format.replace(/[^\d\,]/g, '') : format.replace(/[^\d\.]/g, '')).split(dec);\r
- \r
- if(1 < psplit.length){\r
- v = v.toFixed(psplit[1].length);\r
- }else if(2 < psplit.length){\r
- throw ('NumberFormatException: invalid format, formats should have no more than 1 period: ' + format);\r
- }else{\r
- v = v.toFixed(0);\r
- }\r
- \r
- var fnum = v.toString();\r
- if(hasComma){\r
- psplit = fnum.split('.');\r
- \r
- var cnum = psplit[0], parr = [], j = cnum.length, m = Math.floor(j / 3), n = cnum.length % 3 || 3;\r
- \r
- for(var i = 0; i < j; i += n){\r
- if(i != 0){\r
- n = 3;\r
- }\r
- parr[parr.length] = cnum.substr(i, n);\r
- m -= 1;\r
- }\r
- fnum = parr.join(comma);\r
- if(psplit[1]){\r
- fnum += dec + psplit[1];\r
- }\r
- }\r
- \r
- return (neg ? '-' : '') + format.replace(/[\d,?\.?]+/, fnum);\r
- },\r
-\r
- <div id="method-Ext.util.Format-numberRenderer"></div>/**\r
- * Returns a number rendering function that can be reused to apply a number format multiple times efficiently\r
- * @param {String} format Any valid number format string for {@link #number}\r
- * @return {Function} The number formatting function\r
- */\r
- numberRenderer : function(format){\r
- return function(v){\r
- return Ext.util.Format.number(v, format);\r
- };\r
- },\r
-\r
- <div id="method-Ext.util.Format-plural"></div>/**\r
- * Selectively do a plural form of a word based on a numeric value. For example, in a template,\r
- * {commentCount:plural("Comment")} would result in "1 Comment" if commentCount was 1 or would be "x Comments"\r
- * if the value is 0 or greater than 1.\r
- * @param {Number} value The value to compare against\r
- * @param {String} singular The singular form of the word\r
- * @param {String} plural (optional) The plural form of the word (defaults to the singular with an "s")\r
- */\r
- plural : function(v, s, p){\r
- return v +' ' + (v == 1 ? s : (p ? p : s+'s'));\r
- },\r
- \r
- <div id="method-Ext.util.Format-nl2br"></div>/**\r
- * Converts newline characters to the HTML tag <br/>\r
- * @param {String} The string value to format.\r
- * @return {String} The string with embedded <br/> tags in place of newlines.\r
- */\r
- nl2br : function(v){\r
- return v === undefined || v === null ? '' : v.replace(/\n/g, '<br/>');\r
- }\r
- }\r
-}();</pre>
+(function() {
+ Ext.ns('Ext.util');
+
+ Ext.util.Format = {};
+ var UtilFormat = Ext.util.Format,
+ stripTagsRE = /<\/?[^>]+>/gi,
+ stripScriptsRe = /(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)/ig,
+ nl2brRe = /\r?\n/g,
+
+ // A RegExp to remove from a number format string, all characters except digits and '.'
+ formatCleanRe = /[^\d\.]/g,
+
+ // A RegExp to remove from a number format string, all characters except digits and the local decimal separator.
+ // Created on first use. The local decimal separator character must be initialized for this to be created.
+ I18NFormatCleanRe;
+
+ Ext.apply(UtilFormat, {
+<span id='Ext-util-Format-property-thousandSeparator'> /**
+</span> * @type String
+ * @property thousandSeparator
+ * <p>The character that the {@link #number} function uses as a thousand separator.</p>
+ * <p>This defaults to <code>,</code>, but may be overridden in a locale file.</p>
+ */
+ thousandSeparator: ',',
+
+<span id='Ext-util-Format-property-decimalSeparator'> /**
+</span> * @type String
+ * @property decimalSeparator
+ * <p>The character that the {@link #number} function uses as a decimal point.</p>
+ * <p>This defaults to <code>.</code>, but may be overridden in a locale file.</p>
+ */
+ decimalSeparator: '.',
+
+<span id='Ext-util-Format-property-currencyPrecision'> /**
+</span> * @type Number
+ * @property currencyPrecision
+ * <p>The number of decimal places that the {@link #currency} function displays.</p>
+ * <p>This defaults to <code>2</code>, but may be overridden in a locale file.</p>
+ */
+ currencyPrecision: 2,
+
+<span id='Ext-util-Format-property-currencySign'> /**
+</span> * @type String
+ * @property currencySign
+ * <p>The currency sign that the {@link #currency} function displays.</p>
+ * <p>This defaults to <code>$</code>, but may be overridden in a locale file.</p>
+ */
+ currencySign: '$',
+
+<span id='Ext-util-Format-property-currencyAtEnd'> /**
+</span> * @type Boolean
+ * @property currencyAtEnd
+ * <p>This may be set to <code>true</code> to make the {@link #currency} function
+ * append the currency sign to the formatted value.</p>
+ * <p>This defaults to <code>false</code>, but may be overridden in a locale file.</p>
+ */
+ currencyAtEnd: false,
+
+<span id='Ext-util-Format-method-undef'> /**
+</span> * Checks a reference and converts it to empty string if it is undefined
+ * @param {Mixed} value Reference to check
+ * @return {Mixed} Empty string if converted, otherwise the original value
+ */
+ undef : function(value) {
+ return value !== undefined ? value : "";
+ },
+
+<span id='Ext-util-Format-method-defaultValue'> /**
+</span> * Checks a reference and converts it to the default value if it's empty
+ * @param {Mixed} value Reference to check
+ * @param {String} defaultValue The value to insert of it's undefined (defaults to "")
+ * @return {String}
+ */
+ defaultValue : function(value, defaultValue) {
+ return value !== undefined && value !== '' ? value : defaultValue;
+ },
+
+<span id='Ext-util-Format-method-substr'> /**
+</span> * Returns a substring from within an original string
+ * @param {String} value The original text
+ * @param {Number} start The start index of the substring
+ * @param {Number} length The length of the substring
+ * @return {String} The substring
+ */
+ substr : function(value, start, length) {
+ return String(value).substr(start, length);
+ },
+
+<span id='Ext-util-Format-method-lowercase'> /**
+</span> * Converts a string to all lower case letters
+ * @param {String} value The text to convert
+ * @return {String} The converted text
+ */
+ lowercase : function(value) {
+ return String(value).toLowerCase();
+ },
+
+<span id='Ext-util-Format-method-uppercase'> /**
+</span> * Converts a string to all upper case letters
+ * @param {String} value The text to convert
+ * @return {String} The converted text
+ */
+ uppercase : function(value) {
+ return String(value).toUpperCase();
+ },
+
+<span id='Ext-util-Format-method-usMoney'> /**
+</span> * Format a number as US currency
+ * @param {Number/String} value The numeric value to format
+ * @return {String} The formatted currency string
+ */
+ usMoney : function(v) {
+ return UtilFormat.currency(v, '$', 2);
+ },
+
+<span id='Ext-util-Format-method-currency'> /**
+</span> * Format a number as a currency
+ * @param {Number/String} value The numeric value to format
+ * @param {String} sign The currency sign to use (defaults to {@link #currencySign})
+ * @param {Number} decimals The number of decimals to use for the currency (defaults to {@link #currencyPrecision})
+ * @param {Boolean} end True if the currency sign should be at the end of the string (defaults to {@link #currencyAtEnd})
+ * @return {String} The formatted currency string
+ */
+ currency: function(v, currencySign, decimals, end) {
+ var negativeSign = '',
+ format = ",0",
+ i = 0;
+ v = v - 0;
+ if (v < 0) {
+ v = -v;
+ negativeSign = '-';
+ }
+ decimals = decimals || UtilFormat.currencyPrecision;
+ format += format + (decimals > 0 ? '.' : '');
+ for (; i < decimals; i++) {
+ format += '0';
+ }
+ v = UtilFormat.number(v, format);
+ if ((end || UtilFormat.currencyAtEnd) === true) {
+ return Ext.String.format("{0}{1}{2}", negativeSign, v, currencySign || UtilFormat.currencySign);
+ } else {
+ return Ext.String.format("{0}{1}{2}", negativeSign, currencySign || UtilFormat.currencySign, v);
+ }
+ },
+
+<span id='Ext-util-Format-method-date'> /**
+</span> * Formats the passed date using the specified format pattern.
+ * @param {String/Date} value The value to format. If a string is passed, it is converted to a Date by the Javascript
+ * Date object's <a href="http://www.w3schools.com/jsref/jsref_parse.asp">parse()</a> method.
+ * @param {String} format (Optional) Any valid date format string. Defaults to {@link Ext.Date#defaultFormat}.
+ * @return {String} The formatted date string.
+ */
+ date: function(v, format) {
+ if (!v) {
+ return "";
+ }
+ if (!Ext.isDate(v)) {
+ v = new Date(Date.parse(v));
+ }
+ return Ext.Date.dateFormat(v, format || Ext.Date.defaultFormat);
+ },
+
+<span id='Ext-util-Format-method-dateRenderer'> /**
+</span> * Returns a date rendering function that can be reused to apply a date format multiple times efficiently
+ * @param {String} format Any valid date format string. Defaults to {@link Ext.Date#defaultFormat}.
+ * @return {Function} The date formatting function
+ */
+ dateRenderer : function(format) {
+ return function(v) {
+ return UtilFormat.date(v, format);
+ };
+ },
+
+<span id='Ext-util-Format-method-stripTags'> /**
+</span> * Strips all HTML tags
+ * @param {Mixed} value The text from which to strip tags
+ * @return {String} The stripped text
+ */
+ stripTags : function(v) {
+ return !v ? v : String(v).replace(stripTagsRE, "");
+ },
+
+<span id='Ext-util-Format-method-stripScripts'> /**
+</span> * Strips all script tags
+ * @param {Mixed} value The text from which to strip script tags
+ * @return {String} The stripped text
+ */
+ stripScripts : function(v) {
+ return !v ? v : String(v).replace(stripScriptsRe, "");
+ },
+
+<span id='Ext-util-Format-method-fileSize'> /**
+</span> * Simple format for a file size (xxx bytes, xxx KB, xxx MB)
+ * @param {Number/String} size The numeric value to format
+ * @return {String} The formatted file size
+ */
+ fileSize : function(size) {
+ if (size < 1024) {
+ return size + " bytes";
+ } else if (size < 1048576) {
+ return (Math.round(((size*10) / 1024))/10) + " KB";
+ } else {
+ return (Math.round(((size*10) / 1048576))/10) + " MB";
+ }
+ },
+
+<span id='Ext-util-Format-method-math'> /**
+</span> * It does simple math for use in a template, for example:<pre><code>
+ * var tpl = new Ext.Template('{value} * 10 = {value:math("* 10")}');
+ * </code></pre>
+ * @return {Function} A function that operates on the passed value.
+ * @method
+ */
+ math : function(){
+ var fns = {};
+
+ return function(v, a){
+ if (!fns[a]) {
+ fns[a] = Ext.functionFactory('v', 'return v ' + a + ';');
+ }
+ return fns[a](v);
+ };
+ }(),
+
+<span id='Ext-util-Format-method-round'> /**
+</span> * Rounds the passed number to the required decimal precision.
+ * @param {Number/String} value The numeric value to round.
+ * @param {Number} precision The number of decimal places to which to round the first parameter's value.
+ * @return {Number} The rounded value.
+ */
+ round : function(value, precision) {
+ var result = Number(value);
+ if (typeof precision == 'number') {
+ precision = Math.pow(10, precision);
+ result = Math.round(value * precision) / precision;
+ }
+ return result;
+ },
+
+<span id='Ext-util-Format-method-number'> /**
+</span> * <p>Formats the passed number according to the passed format string.</p>
+ * <p>The number of digits after the decimal separator character specifies the number of
+ * decimal places in the resulting string. The <u>local-specific</u> decimal character is used in the result.</p>
+ * <p>The <i>presence</i> of a thousand separator character in the format string specifies that
+ * the <u>locale-specific</u> thousand separator (if any) is inserted separating thousand groups.</p>
+ * <p>By default, "," is expected as the thousand separator, and "." is expected as the decimal separator.</p>
+ * <p><b>New to Ext4</b></p>
+ * <p>Locale-specific characters are always used in the formatted output when inserting
+ * thousand and decimal separators.</p>
+ * <p>The format string must specify separator characters according to US/UK conventions ("," as the
+ * thousand separator, and "." as the decimal separator)</p>
+ * <p>To allow specification of format strings according to local conventions for separator characters, add
+ * the string <code>/i</code> to the end of the format string.</p>
+ * <div style="margin-left:40px">examples (123456.789):
+ * <div style="margin-left:10px">
+ * 0 - (123456) show only digits, no precision<br>
+ * 0.00 - (123456.78) show only digits, 2 precision<br>
+ * 0.0000 - (123456.7890) show only digits, 4 precision<br>
+ * 0,000 - (123,456) show comma and digits, no precision<br>
+ * 0,000.00 - (123,456.78) show comma and digits, 2 precision<br>
+ * 0,0.00 - (123,456.78) shortcut method, show comma and digits, 2 precision<br>
+ * To allow specification of the formatting string using UK/US grouping characters (,) and decimal (.) for international numbers, add /i to the end.
+ * For example: 0.000,00/i
+ * </div></div>
+ * @param {Number} v The number to format.
+ * @param {String} format The way you would like to format this text.
+ * @return {String} The formatted number.
+ */
+ number:
+ function(v, formatString) {
+ if (!formatString) {
+ return v;
+ }
+ v = Ext.Number.from(v, NaN);
+ if (isNaN(v)) {
+ return '';
+ }
+ var comma = UtilFormat.thousandSeparator,
+ dec = UtilFormat.decimalSeparator,
+ i18n = false,
+ neg = v < 0,
+ hasComma,
+ psplit;
+
+ v = Math.abs(v);
+
+ // The "/i" suffix allows caller to use a locale-specific formatting string.
+ // Clean the format string by removing all but numerals and the decimal separator.
+ // Then split the format string into pre and post decimal segments according to *what* the
+ // decimal separator is. If they are specifying "/i", they are using the local convention in the format string.
+ if (formatString.substr(formatString.length - 2) == '/i') {
+ if (!I18NFormatCleanRe) {
+ I18NFormatCleanRe = new RegExp('[^\\d\\' + UtilFormat.decimalSeparator + ']','g');
+ }
+ formatString = formatString.substr(0, formatString.length - 2);
+ i18n = true;
+ hasComma = formatString.indexOf(comma) != -1;
+ psplit = formatString.replace(I18NFormatCleanRe, '').split(dec);
+ } else {
+ hasComma = formatString.indexOf(',') != -1;
+ psplit = formatString.replace(formatCleanRe, '').split('.');
+ }
+
+ if (1 < psplit.length) {
+ v = v.toFixed(psplit[1].length);
+ } else if(2 < psplit.length) {
+ //<debug>
+ Ext.Error.raise({
+ sourceClass: "Ext.util.Format",
+ sourceMethod: "number",
+ value: v,
+ formatString: formatString,
+ msg: "Invalid number format, should have no more than 1 decimal"
+ });
+ //</debug>
+ } else {
+ v = v.toFixed(0);
+ }
+
+ var fnum = v.toString();
+
+ psplit = fnum.split('.');
+
+ if (hasComma) {
+ var cnum = psplit[0],
+ parr = [],
+ j = cnum.length,
+ m = Math.floor(j / 3),
+ n = cnum.length % 3 || 3,
+ i;
+
+ for (i = 0; i < j; i += n) {
+ if (i !== 0) {
+ n = 3;
+ }
+
+ parr[parr.length] = cnum.substr(i, n);
+ m -= 1;
+ }
+ fnum = parr.join(comma);
+ if (psplit[1]) {
+ fnum += dec + psplit[1];
+ }
+ } else {
+ if (psplit[1]) {
+ fnum = psplit[0] + dec + psplit[1];
+ }
+ }
+
+ return (neg ? '-' : '') + formatString.replace(/[\d,?\.?]+/, fnum);
+ },
+
+<span id='Ext-util-Format-method-numberRenderer'> /**
+</span> * Returns a number rendering function that can be reused to apply a number format multiple times efficiently
+ * @param {String} format Any valid number format string for {@link #number}
+ * @return {Function} The number formatting function
+ */
+ numberRenderer : function(format) {
+ return function(v) {
+ return UtilFormat.number(v, format);
+ };
+ },
+
+<span id='Ext-util-Format-method-plural'> /**
+</span> * Selectively do a plural form of a word based on a numeric value. For example, in a template,
+ * {commentCount:plural("Comment")} would result in "1 Comment" if commentCount was 1 or would be "x Comments"
+ * if the value is 0 or greater than 1.
+ * @param {Number} value The value to compare against
+ * @param {String} singular The singular form of the word
+ * @param {String} plural (optional) The plural form of the word (defaults to the singular with an "s")
+ */
+ plural : function(v, s, p) {
+ return v +' ' + (v == 1 ? s : (p ? p : s+'s'));
+ },
+
+<span id='Ext-util-Format-method-nl2br'> /**
+</span> * Converts newline characters to the HTML tag &lt;br/>
+ * @param {String} The string value to format.
+ * @return {String} The string with embedded &lt;br/> tags in place of newlines.
+ */
+ nl2br : function(v) {
+ return Ext.isEmpty(v) ? '' : v.replace(nl2brRe, '<br/>');
+ },
+
+<span id='Ext-util-Format-method-capitalize'> /**
+</span> * Capitalize the given string. See {@link Ext.String#capitalize}.
+ * @method
+ */
+ capitalize: Ext.String.capitalize,
+
+<span id='Ext-util-Format-method-ellipsis'> /**
+</span> * Truncate a string and add an ellipsis ('...') to the end if it exceeds the specified length.
+ * See {@link Ext.String#ellipsis}.
+ * @method
+ */
+ ellipsis: Ext.String.ellipsis,
+
+<span id='Ext-util-Format-method-format'> /**
+</span> * Formats to a string. See {@link Ext.String#format}
+ * @method
+ */
+ format: Ext.String.format,
+
+<span id='Ext-util-Format-method-htmlDecode'> /**
+</span> * Convert certain characters (&, <, >, and ') from their HTML character equivalents.
+ * See {@link Ext.string#htmlDecode}.
+ * @method
+ */
+ htmlDecode: Ext.String.htmlDecode,
+
+<span id='Ext-util-Format-method-htmlEncode'> /**
+</span> * Convert certain characters (&, <, >, and ') to their HTML character equivalents for literal display in web pages.
+ * See {@link Ext.String#htmlEncode}.
+ * @method
+ */
+ htmlEncode: Ext.String.htmlEncode,
+
+<span id='Ext-util-Format-method-leftPad'> /**
+</span> * Adds left padding to a string. See {@link Ext.String#leftPad}
+ * @method
+ */
+ leftPad: Ext.String.leftPad,
+
+<span id='Ext-util-Format-method-trim'> /**
+</span> * Trims any whitespace from either side of a string. See {@link Ext.String#trim}.
+ * @method
+ */
+ trim : Ext.String.trim,
+
+<span id='Ext-util-Format-method-parseBox'> /**
+</span> * Parses a number or string representing margin sizes into an object. Supports CSS-style margin declarations
+ * (e.g. 10, "10", "10 10", "10 10 10" and "10 10 10 10" are all valid options and would return the same result)
+ * @param {Number|String} v The encoded margins
+ * @return {Object} An object with margin sizes for top, right, bottom and left
+ */
+ parseBox : function(box) {
+ if (Ext.isNumber(box)) {
+ box = box.toString();
+ }
+ var parts = box.split(' '),
+ ln = parts.length;
+
+ if (ln == 1) {
+ parts[1] = parts[2] = parts[3] = parts[0];
+ }
+ else if (ln == 2) {
+ parts[2] = parts[0];
+ parts[3] = parts[1];
+ }
+ else if (ln == 3) {
+ parts[3] = parts[1];
+ }
+
+ return {
+ top :parseInt(parts[0], 10) || 0,
+ right :parseInt(parts[1], 10) || 0,
+ bottom:parseInt(parts[2], 10) || 0,
+ left :parseInt(parts[3], 10) || 0
+ };
+ },
+
+<span id='Ext-util-Format-method-escapeRegex'> /**
+</span> * Escapes the passed string for use in a regular expression
+ * @param {String} str
+ * @return {String}
+ */
+ escapeRegex : function(s) {
+ return s.replace(/([\-.*+?\^${}()|\[\]\/\\])/g, "\\$1");
+ }
+ });
+})();
+</pre>
</body>
-</html>
\ No newline at end of file
+</html>