Changeset 12862
- Timestamp:
- 03/03/08 18:09:37 (10 months ago)
- Files:
-
- 1 modified
-
dojo/trunk/number.js (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
dojo/trunk/number.js
r11695 r12862 12 12 } 13 13 14 dojo.number.__ formatOptions = function(kwArgs){14 dojo.number.__FormatOptions = function(){ 15 15 // pattern: String? 16 16 // override formatting pattern with this string (see … … 22 22 // fixed number of decimal places to show. This overrides any 23 23 // information in the provided pattern. 24 // round: N Umber?24 // round: Number? 25 25 // 5 rounds to nearest .5; 0 rounds to nearest whole (default). -1 26 26 // means don't round. … … 31 31 // locale: String? 32 32 // override the locale used to determine formatting rules 33 this.pattern = pattern; 34 this.type = type; 35 this.places = places; 36 this.round = round; 37 this.currency = currency; 38 this.symbol = symbol; 39 this.locale = locale; 33 40 } 34 41 =====*/ 35 42 36 dojo.number.format = function(/*Number*/value, /*dojo.number.__ formatOptions?*/options){43 dojo.number.format = function(/*Number*/value, /*dojo.number.__FormatOptions?*/options){ 37 44 // summary: 38 45 // Format a Number as a String, using locale-specific settings … … 40 47 // Create a string from a Number using a known localized pattern. 41 48 // Formatting patterns appropriate to the locale are chosen from the 42 // CLDR http://unicode.org/cldras well as the appropriate symbols and43 // delimiters. See http://www.unicode.org/reports/tr35/#Number_Elements49 // [CLDR](http://unicode.org/cldr) as well as the appropriate symbols and 50 // delimiters. See <http://www.unicode.org/reports/tr35/#Number_Elements> 44 51 // value: 45 52 // the number to be formatted. If not a valid JavaScript number, … … 58 65 dojo.number._numberPatternRE = /[#0,]*[#0](?:\.0*#*)?/; // not precise, but good enough 59 66 60 dojo.number._applyPattern = function(/*Number*/value, /*String*/pattern, /*dojo.number.__ formatOptions?*/options){67 dojo.number._applyPattern = function(/*Number*/value, /*String*/pattern, /*dojo.number.__FormatOptions?*/options){ 61 68 // summary: 62 69 // Apply pattern to format value as a string using options. Gives no … … 65 72 // the number to be formatted. 66 73 // pattern: 67 // a pattern string as described in68 // http://www.unicode.org/reports/tr35/#Number_Format_Patterns69 // options: dojo.number.__ formatOptions?70 // _applyPattern is usually called via dojo.number.format()which74 // a pattern string as described by 75 // [unicode.org TR35](http://www.unicode.org/reports/tr35/#Number_Format_Patterns) 76 // options: dojo.number.__FormatOptions? 77 // _applyPattern is usually called via `dojo.number.format()` which 71 78 // populates an extra property in the options parameter, "customs". 72 79 // The customs object specifies group and decimal parameters if set. … … 136 143 137 144 /*===== 138 dojo.number.__ formatAbsoluteOptions = function(kwArgs){145 dojo.number.__FormatAbsoluteOptions = function(){ 139 146 // decimal: String? 140 147 // the decimal separator … … 146 153 // 5 rounds to nearest .5; 0 rounds to nearest whole (default). -1 147 154 // means don't round. 155 this.decimal = decimal; 156 this.group = group; 157 this.places = places; 158 this.round = round; 148 159 } 149 160 =====*/ 150 161 151 dojo.number._formatAbsolute = function(/*Number*/value, /*String*/pattern, /*dojo.number.__ formatAbsoluteOptions?*/options){162 dojo.number._formatAbsolute = function(/*Number*/value, /*String*/pattern, /*dojo.number.__FormatAbsoluteOptions?*/options){ 152 163 // summary: 153 164 // Apply numeric pattern to absolute value using options. Gives no … … 156 167 // the number to be formatted, ignores sign 157 168 // pattern: 158 // the number portion of a pattern (e.g. #,##0.00)169 // the number portion of a pattern (e.g. `#,##0.00`) 159 170 options = options || {}; 160 171 if(options.places === true){options.places=0;} … … 229 240 230 241 /*===== 231 dojo.number.__ regexpOptions = function(kwArgs){242 dojo.number.__RegexpOptions = function(){ 232 243 // pattern: String? 233 244 // override pattern with this string. Default is provided based on … … 243 254 // number of decimal places to accept: Infinity, a positive number, or 244 255 // a range "n,m". By default, defined by pattern. 256 this.pattern = pattern; 257 this.type = type; 258 this.locale = locale; 259 this.strict = strict; 260 this.places = places; 245 261 } 246 262 =====*/ 247 dojo.number.regexp = function(/*dojo.number.__ regexpOptions?*/options){263 dojo.number.regexp = function(/*dojo.number.__RegexpOptions?*/options){ 248 264 // summary: 249 265 // Builds the regular needed to parse a number … … 295 311 if(parts.length == 1 || places === 0){flags.fractional = false;} 296 312 else{ 297 if( typeof places == "undefined"){ places = parts[1].lastIndexOf('0')+1; }313 if(places === undefined){ places = parts[1].lastIndexOf('0')+1; } 298 314 if(places && options.fractional == undefined){flags.fractional = true;} // required fractional, unless otherwise specified 299 315 if(!options.places && (places < parts[1].length)){ places += "," + parts[1].length; } … … 334 350 335 351 /*===== 336 dojo.number.__ parseOptions = function(kwArgs){352 dojo.number.__ParseOptions = function(){ 337 353 // pattern: String 338 354 // override pattern with this string. Default is provided based on … … 347 363 // currency: Object 348 364 // object with currency information 365 this.pattern = pattern; 366 this.type = type; 367 this.locale = locale; 368 this.strict = strict; 369 this.currency = currency; 349 370 } 350 371 =====*/ 351 dojo.number.parse = function(/*String*/expression, /*dojo.number.__ parseOptions?*/options){372 dojo.number.parse = function(/*String*/expression, /*dojo.number.__ParseOptions?*/options){ 352 373 // summary: 353 374 // Convert a properly formatted string to a primitive Number, using … … 355 376 // description: 356 377 // Create a Number from a string using a known localized pattern. 357 // Formatting patterns are chosen appropriate to the locale .358 // Formatting patterns are implemented using the syntax described at359 // *URL*378 // Formatting patterns are chosen appropriate to the locale 379 // and follow the syntax described by 380 // [unicode.org TR35](http://www.unicode.org/reports/tr35/#Number_Format_Patterns) 360 381 // expression: 361 382 // A string representation of a Number … … 385 406 386 407 /*===== 387 dojo.number.__ realNumberRegexpFlags = function(kwArgs){408 dojo.number.__RealNumberRegexpFlags = function(){ 388 409 // places: Number? 389 410 // The integer number of decimal places or a range given as "n,m". If … … 405 426 // match if it is signed or unsigned). flags in regexp.integer can be 406 427 // applied. 428 this.places = places; 429 this.decimal = decimal; 430 this.fractional = fractional; 431 this.exponent = exponent; 432 this.eSigned = eSigned; 407 433 } 408 434 =====*/ 409 435 410 dojo.number._realNumberRegexp = function(/*dojo.number.__ realNumberRegexpFlags?*/flags){436 dojo.number._realNumberRegexp = function(/*dojo.number.__RealNumberRegexpFlags?*/flags){ 411 437 // summary: 412 438 // Builds a regular expression to match a real number in exponential 413 439 // notation 414 // flags:415 // An object416 440 417 441 // assign default values to missing paramters 418 442 flags = flags || {}; 419 if(typeof flags.places == "undefined"){ flags.places = Infinity; } 443 //TODO: use mixin instead? 444 if(!("places" in flags)){ flags.places = Infinity; } 420 445 if(typeof flags.decimal != "string"){ flags.decimal = "."; } 421 if( typeof flags.fractional == "undefined"|| /^0/.test(flags.places)){ flags.fractional = [true, false]; }422 if( typeof flags.exponent == "undefined"){ flags.exponent = [true, false]; }423 if( typeof flags.eSigned == "undefined"){ flags.eSigned = [true, false]; }446 if(!("fractional" in flags) || /^0/.test(flags.places)){ flags.fractional = [true, false]; } 447 if(!("exponent" in flags)){ flags.exponent = [true, false]; } 448 if(!("eSigned" in flags)){ flags.eSigned = [true, false]; } 424 449 425 450 // integer RE … … 459 484 460 485 /*===== 461 dojo.number.__ integerRegexpFlags = function(kwArgs){486 dojo.number.__IntegerRegexpFlags = function(){ 462 487 // signed: Boolean? 463 // The leading plus-or-minus sign. Can be true, false, or [true,464 // false]. Default is [true, false], (i.e. will match if it is signed488 // The leading plus-or-minus sign. Can be true, false, or `[true,false]`. 489 // Default is `[true, false]`, (i.e. will match if it is signed 465 490 // or unsigned). 466 491 // separator: String? 467 492 // The character used as the thousands separator. Default is no 468 // separator. For more than one symbol use an array, e.g. [",", ""],493 // separator. For more than one symbol use an array, e.g. `[",", ""]`, 469 494 // makes ',' optional. 470 495 // groupSize: Number? 471 496 // group size between separators 472 // flags.groupSize2: Number? 473 // second grouping (for India) 497 // groupSize2: Number? 498 // second grouping, where separators 2..n have a different interval than the first separator (for India) 499 this.signed = signed; 500 this.separator = separator; 501 this.groupSize = groupSize; 502 this.groupSize2 = groupSize2; 474 503 } 475 504 =====*/ 476 505 477 dojo.number._integerRegexp = function(/*dojo.number.__ integerRegexpFlags?*/flags){506 dojo.number._integerRegexp = function(/*dojo.number.__IntegerRegexpFlags?*/flags){ 478 507 // summary: 479 508 // Builds a regular expression that matches an integer 480 // flags:481 // An object482 509 483 510 // assign default values to missing paramters 484 511 flags = flags || {}; 485 if( typeof flags.signed == "undefined"){ flags.signed = [true, false]; }486 if( typeof flags.separator == "undefined"){512 if(!("signed" in flags)){ flags.signed = [true, false]; } 513 if(!("separator" in flags)){ 487 514 flags.separator = ""; 488 }else if( typeof flags.groupSize == "undefined"){515 }else if(!("groupSize" in flags)){ 489 516 flags.groupSize = 3; 490 517 }