UNPKG

@kcuf/intl-formatter

Version:
17 lines (16 loc) 782 B
import _slicedToArray from "@babel/runtime/helpers/slicedToArray"; /** * 数值展示组件,对数值进行格式化展示 1234 -> 1,234 */ export default function formatNumberFallback(n) { var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -1; var nInString = precision >= 0 ? n.toFixed(precision) : String(n); var _ref = nInString.split('.'), _ref2 = _slicedToArray(_ref, 2), wholePart = _ref2[0], _ref2$ = _ref2[1], fractionPart = _ref2$ === void 0 ? '' : _ref2$; var formattedWholePart = wholePart.replace(/\B(?=(\d{3})+(?!\d))/g, ','); // 整数部分加逗号 return fractionPart ? "".concat(formattedWholePart, ".").concat(fractionPart) : formattedWholePart; } //# sourceMappingURL=format-number-fallback.js.map