* Decimal adjustment of a number. * * @param {String} type The type of adjustment. * @param {Number} value The number. * @param {Integer} exp The exponent (the 10 logarithm of the adjustment base). * @returns {Number} The adjusted value.
(type, value, exp)
| 689 | * @returns {Number} The adjusted value. |
| 690 | */ |
| 691 | function decimalAdjust(type, value, exp) { |
| 692 | // If the exp is undefined or zero... |
| 693 | if (typeof exp === 'undefined' || +exp === 0) { |
| 694 | return Math[type](value); |
| 695 | } |
| 696 | value = +value; |
| 697 | exp = +exp; |
| 698 | // If the value is not a number or the exp is not an integer... |
| 699 | if (isNaN(value) || exp % 1 !== 0) { |
| 700 | return NaN; |
| 701 | } |
| 702 | // Shift |
| 703 | value = value.toString().split('e'); |
| 704 | value = Math[type](+(value[0] + 'e' + (value[1] ? (+value[1] - exp) : -exp))); |
| 705 | // Shift back |
| 706 | value = value.toString().split('e'); |
| 707 | return +(value[0] + 'e' + (value[1] ? (+value[1] + exp) : exp)); |
| 708 | } |
| 709 | |
| 710 | // Decimal round |
| 711 | if (!Math.round10) { |