PageSourceSearch

https://www.dvo.com/cookn-util/number.js

js dvo.com collected 2026-09-24 09:16:53 UTC 680 bytes, 25 lines download raw bytes

1/**
2 * Shortens the given number so that:
3 *  • 109,893 will become 109K
4 *  • 8,388 will become 8.3K
5 *  • 9,040,444 will become 9M
6 */
7function shortenNumber(num, zeroValue) {
8    if (num === 0) {
9        return zeroValue;
10    }
11    var numStr = num.toString();
12    if (num >= 1000000) {
13        numStr = (num / 1000000).toFixed(1) + 'M';
14    } else if (num >= 10000) {
15        numStr = (Math.floor(num / 1000)) + 'K';
16    } else if (num >= 1000) {
17        numStr = (num / 1000).toFixed(1) + 'K';
18    }
19    numStr = _replaceAll(numStr, "\\.0", "");
20    return numStr;
21}
22
23function _replaceAll(str, find, replace) {
24    return str.replace(new RegExp(find, 'g'), replace);
25}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.