* (1) Fix rounding error of float numbers. * (2) Support return string to avoid scientific notation like '3.5e-7'. * * @param {number} x * @param {number} [precision] * @param {boolean} [returnStr] * @return {number|string}
(x, precision, returnStr)
| 18948 | * @return {number|string} |
| 18949 | */ |
| 18950 | function round$1(x, precision, returnStr) { |
| 18951 | if (precision == null) { |
| 18952 | precision = 10; |
| 18953 | } |
| 18954 | // Avoid range error |
| 18955 | precision = Math.min(Math.max(0, precision), 20); |
| 18956 | x = (+x).toFixed(precision); |
| 18957 | return returnStr ? x : +x; |
| 18958 | } |
| 18959 | |
| 18960 | /** |
| 18961 | * asc sort arr. |
no test coverage detected