MCPcopy
hub / github.com/apache/echarts / getPrecision

Function getPrecision

test/lib/testHelper.js:3196–3221  ·  view source on GitHub ↗

* Copied from src/util/number.ts

(val)

Source from the content-addressed store, hash-verified

3194 * Copied from src/util/number.ts
3195 */
3196 function getPrecision(val) {
3197 val = +val;
3198 if (isNaN(val)) {
3199 return 0;
3200 }
3201
3202 // It is much faster than methods converting number to string as follows
3203 // let tmp = val.toString();
3204 // return tmp.length - 1 - tmp.indexOf('.');
3205 // especially when precision is low
3206 // Notice:
3207 // (1) If the loop count is over about 20, it is slower than `getPrecisionSafe`.
3208 // (see https://jsbench.me/2vkpcekkvw/1)
3209 // (2) If the val is less than for example 1e-15, the result may be incorrect.
3210 // (see test/ut/spec/util/number.test.ts `getPrecision_equal_random`)
3211 if (val > 1e-14) {
3212 var e = 1;
3213 for (var i = 0; i < 15; i++, e *= 10) {
3214 if (Math.round(val * e) / e === val) {
3215 return i;
3216 }
3217 }
3218 }
3219
3220 return getPrecisionSafe(val);
3221 }
3222
3223 /**
3224 * Copied from src/util/number.ts

Callers 1

createRangeInputFunction · 0.70

Calls 1

getPrecisionSafeFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…