Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 9x 9x 9x 2x | /** * 将数据类型转为整数数字,转换失败则返回一个默认值 * @method num/numerical * @param {*} str 要转换的数据 * @param {Number} [def=0] 转换失败时的默认值 * @param {Number} [sys=10] 进制 * @return {Number} 转换而得的整数 * @example * var $numerical = require('@spore-ui/kit/packages/num/numerical'); * $numerical('10x'); // 10 * $numerical('x10'); // 0 */ function numerical(str, def, sys) { def = def || 0; sys = sys || 10; return parseInt(str, sys) || def; } module.exports = numerical; |