dtable-utils
Advanced tools
Comparing version 4.2.3 to 4.2.4
import { NPminus as minus } from '../helper/number-precision/index.js'; | ||
import { round } from '../number.js'; | ||
import { getDurationDisplayString } from './duration.js'; | ||
@@ -69,16 +70,2 @@ import { DEFAULT_NUMBER_FORMAT } from '../constants/column.js'; | ||
}; | ||
var round = function round(number) { | ||
var decimalDigits = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
if (decimalDigits === 0) { | ||
return Math.round(number); | ||
} | ||
var offsets = Math.pow(10, decimalDigits); | ||
var fixedNum = number * offsets; | ||
if (decimalDigits > 0) { | ||
// unexpected precision problem | ||
// e.g. round(8330.845, 2): 8330.845 * 100 = 833084.4999999999 | ||
fixedNum = Number.parseFloat(fixedNum.toFixed(1)); | ||
} | ||
return Math.round(fixedNum) / offsets; | ||
}; | ||
var toThousands = function toThousands(number, _ref2) { | ||
@@ -269,2 +256,2 @@ var formats = _ref2.formats, | ||
export { getNumberDisplayString, getPrecisionNumber, replaceNumberNotAllowInput, round }; | ||
export { getNumberDisplayString, getPrecisionNumber, replaceNumberNotAllowInput }; |
import { NPdivide as divide } from '../helper/number-precision/index.js'; | ||
import { isNumber } from '../number.js'; | ||
import { round, isNumber } from '../number.js'; | ||
import { DURATION_FORMATS_MAP, DURATION_FORMATS } from '../constants/column.js'; | ||
@@ -50,3 +50,3 @@ | ||
var fixedPrecision = format === 'percent' ? precision + 2 : precision; | ||
value = Number(parseFloat(value).toFixed(fixedPrecision)); | ||
value = parseFloat(round(value, fixedPrecision).toFixed(fixedPrecision)); | ||
} | ||
@@ -53,0 +53,0 @@ return value; |
@@ -24,3 +24,3 @@ export { CellType } from './constants/cell-type.js'; | ||
export { getDurationDisplayString } from './cell-value-get/duration.js'; | ||
export { getNumberDisplayString, getPrecisionNumber, replaceNumberNotAllowInput, round } from './cell-value-get/number.js'; | ||
export { getNumberDisplayString, getPrecisionNumber, replaceNumberNotAllowInput } from './cell-value-get/number.js'; | ||
export { getColumnOptionNameById, getMultipleOptionName, getOption, getOptionName } from './cell-value-get/option.js'; | ||
@@ -40,3 +40,3 @@ export { getCollaborator, getCollaboratorsName, getCollaboratorsNames } from './cell-value-get/collaborator.js'; | ||
export { DateUtils } from './date.js'; | ||
export { isNumber, isNumberEqual } from './number.js'; | ||
export { isNumber, isNumberEqual, round } from './number.js'; | ||
export { ValidateFilter } from './validate/filter.js'; | ||
@@ -43,0 +43,0 @@ export { isValidEmail } from './validate/email.js'; |
@@ -21,2 +21,23 @@ /** | ||
export { isNumber, isNumberEqual }; | ||
/** | ||
* Math.round(number) with digits | ||
* @param {number} number | ||
* @param {number} decimalDigits, default as 0 | ||
* @returns number | ||
*/ | ||
var round = function round(number) { | ||
var decimalDigits = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
if (decimalDigits === 0) { | ||
return Math.round(number); | ||
} | ||
var offsets = Math.pow(10, decimalDigits); | ||
var fixedNum = number * offsets; | ||
if (decimalDigits > 0) { | ||
// unexpected precision problem | ||
// e.g. round(8330.845, 2): 8330.845 * 100 = 833084.4999999999 | ||
fixedNum = Number.parseFloat(fixedNum.toFixed(1)); | ||
} | ||
return Math.round(fixedNum) / offsets; | ||
}; | ||
export { isNumber, isNumberEqual, round }; |
@@ -6,2 +6,3 @@ 'use strict'; | ||
var index = require('../helper/number-precision/index.js'); | ||
var number = require('../number.js'); | ||
var duration = require('./duration.js'); | ||
@@ -74,17 +75,3 @@ var column = require('../constants/column.js'); | ||
}; | ||
var round = function round(number) { | ||
var decimalDigits = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
if (decimalDigits === 0) { | ||
return Math.round(number); | ||
} | ||
var offsets = Math.pow(10, decimalDigits); | ||
var fixedNum = number * offsets; | ||
if (decimalDigits > 0) { | ||
// unexpected precision problem | ||
// e.g. round(8330.845, 2): 8330.845 * 100 = 833084.4999999999 | ||
fixedNum = Number.parseFloat(fixedNum.toFixed(1)); | ||
} | ||
return Math.round(fixedNum) / offsets; | ||
}; | ||
var toThousands = function toThousands(number, _ref2) { | ||
var toThousands = function toThousands(number$1, _ref2) { | ||
var formats = _ref2.formats, | ||
@@ -104,6 +91,6 @@ _ref2$isCurrency = _ref2.isCurrency, | ||
// handle numbers in scientific notation | ||
if (String(number).includes('e')) { | ||
if (number < 1 && number > -1) { | ||
if (String(number$1).includes('e')) { | ||
if (number$1 < 1 && number$1 > -1) { | ||
// 1.convert to non-scientific number | ||
var numericString = number.toFixed(enable_precision ? precision : 8); | ||
var numericString = number$1.toFixed(enable_precision ? precision : 8); | ||
@@ -121,8 +108,8 @@ // 2.remove 0 from end of the number which not set precision. e.g. 0.100000 | ||
} | ||
return String(number); | ||
return String(number$1); | ||
} | ||
var decimalString = separatorMap[decimal]; | ||
var thousandsString = separatorMap[thousands]; | ||
var decimalDigits = enable_precision ? precision : getDecimalDigitsFromNumber(number); | ||
var floatNumber = parseFloat(round(number, decimalDigits).toFixed(decimalDigits)); | ||
var decimalDigits = enable_precision ? precision : getDecimalDigitsFromNumber(number$1); | ||
var floatNumber = parseFloat(number.round(number$1, decimalDigits).toFixed(decimalDigits)); | ||
var isMinus = floatNumber < 0; | ||
@@ -279,2 +266,1 @@ var integer = Math.trunc(floatNumber); | ||
exports.replaceNumberNotAllowInput = replaceNumberNotAllowInput; | ||
exports.round = round; |
@@ -54,3 +54,3 @@ 'use strict'; | ||
var fixedPrecision = format === 'percent' ? precision + 2 : precision; | ||
value = Number(parseFloat(value).toFixed(fixedPrecision)); | ||
value = parseFloat(number.round(value, fixedPrecision).toFixed(fixedPrecision)); | ||
} | ||
@@ -57,0 +57,0 @@ return value; |
@@ -164,3 +164,2 @@ 'use strict'; | ||
exports.replaceNumberNotAllowInput = number.replaceNumberNotAllowInput; | ||
exports.round = number.round; | ||
exports.getColumnOptionNameById = option.getColumnOptionNameById; | ||
@@ -197,2 +196,3 @@ exports.getMultipleOptionName = option.getMultipleOptionName; | ||
exports.isNumberEqual = number$3.isNumberEqual; | ||
exports.round = number$3.round; | ||
exports.ValidateFilter = filter.ValidateFilter; | ||
@@ -199,0 +199,0 @@ exports.isValidEmail = email.isValidEmail; |
@@ -25,3 +25,25 @@ 'use strict'; | ||
/** | ||
* Math.round(number) with digits | ||
* @param {number} number | ||
* @param {number} decimalDigits, default as 0 | ||
* @returns number | ||
*/ | ||
var round = function round(number) { | ||
var decimalDigits = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
if (decimalDigits === 0) { | ||
return Math.round(number); | ||
} | ||
var offsets = Math.pow(10, decimalDigits); | ||
var fixedNum = number * offsets; | ||
if (decimalDigits > 0) { | ||
// unexpected precision problem | ||
// e.g. round(8330.845, 2): 8330.845 * 100 = 833084.4999999999 | ||
fixedNum = Number.parseFloat(fixedNum.toFixed(1)); | ||
} | ||
return Math.round(fixedNum) / offsets; | ||
}; | ||
exports.isNumber = isNumber; | ||
exports.isNumberEqual = isNumberEqual; | ||
exports.round = round; |
{ | ||
"name": "dtable-utils", | ||
"version": "4.2.3", | ||
"version": "4.2.4", | ||
"description": "dtable common utils", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
662222
14769