(x: number | string, precision: number, returnStr?: boolean)
| 220 | export function round(x: number | string, precision: number, returnStr: false): number; |
| 221 | export function round(x: number | string, precision: number, returnStr: true): string; |
| 222 | export function round(x: number | string, precision: number, returnStr?: boolean): string | number { |
| 223 | if (__DEV__) { |
| 224 | // NOTICE: We should not provided a default precision, since there is no universally adaptable |
| 225 | // precision. The caller need to input a precision according to the scenarios. |
| 226 | zrUtil.assert(precision != null); |
| 227 | } |
| 228 | if (isNaN(precision)) { |
| 229 | // precision utils (such as getAcceptableTickPrecision) may return NaN. |
| 230 | return returnStr ? '' + x : +x; |
| 231 | } |
| 232 | // Avoid range error |
| 233 | precision = mathMin(mathMax(0, precision), TO_FIXED_SUPPORTED_PRECISION_MAX); |
| 234 | // PENDING: 1.005.toFixed(2) is '1.00' rather than '1.01' |
| 235 | x = (+x).toFixed(precision); |
| 236 | return (returnStr ? x : +x); |
| 237 | } |
| 238 | |
| 239 | export function roundLegacy(x: number | string, precision?: number): number; |
| 240 | export function roundLegacy(x: number | string, precision: number, returnStr: false): number; |
no test coverage detected
searching dependent graphs…