/* * Exposes number format capability * * @copyright Copyright (c) 2013 Kevin van Zonneveld (http://kvz.io) and Contributors (http://phpjs.org/authors). * @license See CREDITS.md * @see https://github.com/kvz/phpjs/blob/ffe1356af23a6f2512c84c954dd4e828e92579fa/functions/strings/number_format.js */ function toFixedFix( n, prec ) { const k = Math.pow( 10, prec ); return '' + ( Math.round( n * k ) / k ).toFixed( prec ); }
function mathProps(mode) { const props = ['E','LN10','LN2','LOG10E','LOG2E','PI','SQRT1_2','SQRT2']; const gpu = new GPU({ mode }); for (let i = 0; i < props.length; i++) { const prop = props[i]; const kernel = gpu.createKernel(`function() { return Math.${prop}; }`, { output: [1] }); assert.equal(kernel()[0].toFixed(6), Math[prop].toFixed(6)); } gpu.destroy(); }
const formatSize = size => { let sizes = [[2, 'M'], [1, 'k']]; while (sizes.length) { let checkSize = sizes.shift(); let limit = Math.pow(1024, checkSize[0]); if (size > limit) { return `${(size / limit).toFixed(2)} ${checkSize[1]}B` } } return `${size} B`; }
const mapper = function mapper(rows) { const filter = function filter() { return _.reduce(rows, (prev, curr) => Math.max(prev, curr.eventLoop.high), 0); }; const maxDelay = filter(); return _.map(rows, (row) => ({ delay: Number(row.eventLoop.delay.toFixed(1)), high: Number(maxDelay.toFixed(1)) })); }
render() { let ratio = this.props.value; ratio /= 1000; let precision = 1; if (ratio < 10) { precision = 2; } else if (ratio >= 100) { precision = 0; } ratio = ratio.toFixed(precision); return <FormattedNumber value={ratio} />; }
function MyType1(v) { this.value = v; this.rawType = true; this.toPostgres = () => { return this.value.toFixed(4); }; }
setInterval(() => { if (count > 0) { console.log(broker.nodeID, ":", padStart(Number(count.toFixed(0)).toLocaleString(), 8), "req/s"); count = 0; } }, 1000);
function buildAtan2KernelResult(mode) { const gpu = new GPU({ mode }); const kernel = gpu.createKernel(function() { return Math.atan2(1, 2); }, { output: [1], }); assert.equal(kernel()[0].toFixed(7), 0.4636476); gpu.destroy(); }
function MyType2(v) { this.value = v; this.rawType = true; this.toPostgres = a => a.value.toFixed(2); }