How to use the round function from mathjs
Find comprehensive JavaScript mathjs.round code examples handpicked from public code repositorys.
mathjs.round is a function that rounds a given number to the nearest integer or a given precision.
GitHub: hollaex/hollaex-kit
131 132 133 134 135 136 137 138 139 140
token: brokerQuote?.token, expiry: brokerQuote?.expiry, type: 'broker' } if (spending_amount != null) { const sourceAmount = math.round( side === 'buy' ? spending_amount / brokerQuote.price : spending_amount * brokerQuote.price, decimalPoint ); responseObj.receiving_amount = sourceAmount;
+ 3 other calls in file
13527 13528 13529 13530 13531 13532 13533 13534 13535 13536 13537 13538
angles[wire].theta = math.round(math.abs(theta), 12); angles[wire].phi = math.round(phi, 12); angles[wire].thetaDeg = math.round(math.multiply(math.abs(theta), (180 / math.pi)), 7); angles[wire].phiDeg = math.round(math.multiply(phi, (180 / math.pi)), 7); angles[wire].radius = math.round(radius, 7); } return angles; };
+ 3791 other calls in file
How does mathjs.round work?
mathjs.round is a function provided by the Math.js library that rounds a number to a specified precision (number of decimal places) or to the nearest integer if no precision is specified. If the number to be rounded is exactly halfway between two possible results, the result will be rounded to the nearest even number, which is a behavior known as "banker's rounding" or "round-to-even". The function can also be used to round the elements of an array or matrix to a specified precision or the nearest integer.
7034 7035 7036 7037 7038 7039 7040 7041 7042
if(!quirkName) { quirkName = "~" + gate.name; if(basicGate.params.length && gate.options.params) { basicGate.params.map(function(param){ angle = math.round(math.evaluate(gate.options.params[param], globalParams), 3); quirkName += "_" + angle; }); }
+ 911 other calls in file
144 145 146 147 148 149 150 151 152 153
key ] ), 3 ); const min = math.round( math.min( benchmarkMetricsCollection[ key ]
+ 2729 other calls in file
Ai Example
1 2 3 4 5 6
const math = require("mathjs"); const num = 1.23456789; const roundedNum = math.round(num, 3); // round to 3 decimal places console.log(roundedNum); // Output: 1.235
In this example, we're using mathjs.round to round the num variable to 3 decimal places, and then logging the result to the console.
GitHub: fwdcp/pugchamp-legacy
![fwdcp profile picture](/fwdcp.png?size=40)
163 164 165 166 167 168 169 170 171 172
if (ret.stats.rating && _.isNumber(doc.stats.rating.mean) && _.isNumber(doc.stats.rating.deviation)) { ret.stats.rating.mean = math.round(doc.stats.rating.mean, 0); ret.stats.rating.deviation = math.round(doc.stats.rating.deviation, 0); ret.stats.rating.low = math.round(doc.stats.rating.low, 0); ret.stats.rating.high = math.round(doc.stats.rating.high, 0); } } else { delete ret.stats.captainScore;
+ 119 other calls in file
GitHub: i5hi/cypherpost
![i5hi profile picture](/i5hi.png?size=40)
7 8 9 10 11 12 13 14 15 16
export function s2b(sats: number): number{ return math.round((sats/SATS_DENOM),8); } export function b2s(bitcoin:number): number{ return math.round(bitcoin*SATS_DENOM,0); } // export function convertExponentialToDecimal(exponentialNumber: number): number|string { // // sanity check - is it exponential number
+ 39 other calls in file
118 119 120 121 122 123 124 125 126 127
function getMathInformationsEnhanced(data) { return { mean: math.round(math.mean(data), 3), /* variance: math.round(math.variance(data, "uncorrected"), 3), */ standardDeviation: math.round(math.std(data), 3), min: math.round(math.min(data), 3), max: math.round(math.max(data), 3), } }
+ 9 other calls in file
GitHub: marcelomf/tbfix
![marcelomf profile picture](/marcelomf.png?size=40)
51 52 53 54 55 56 57 58 59 60
percentD.push(mathjs.mean(dData)) } } s.period[key + '_K'] = percentK[0] == 0 ? 0 : mathjs.round(percentK[0], 2) s.period[key + '_D'] = percentD[0] == 0 ? 0 : mathjs.round(percentD[0], 2) //console.log('lib.srsi: For RSI', RSI[RSI.length - 1], '-', '%K is', s.period[key + '_K'], ', %D is', s.period[key + '_D'], ', period info', s.period); } }
+ 3 other calls in file
GitHub: jly36963/notes
![jly36963 profile picture](/jly36963.png?size=40)
49 50 51 52 53 54 55 56 57 58
// abs math.abs(a); // absolute value // round math.floor(a) // round in negative direction math.round(a) // round to nearest int math.ceil(a); // round in positive direction math.fix(a) // round towards zero // factors & multiples
+ 2 other calls in file
374 375 376 377 378 379 380 381 382 383
* @param {*} playerId * @param {*} traderId */ static setTraderStanding(playerId, traderId, value) { const profile = AccountController.getPmcProfile(playerId); profile.TradersInfo[traderId].standing = mathjs.round(value, 3); } /** * Get player loyalty LEVEL for current trader...
+ 285 other calls in file
902 903 904 905 906 907 908 909 910 911
continue; } let similarUsedPosition = currentUsedPositions.find(p => mathjs.round(p.x, 3) == mathjs.round(lootData.Position.x, 3) && mathjs.round(p.y, 3) == mathjs.round(lootData.Position.y, 3) && mathjs.round(p.z, 3) == mathjs.round(lootData.Position.z, 3) ); if(similarUsedPosition !== undefined ) {
+ 986 other calls in file
87 88 89 90 91 92 93 94 95
// Angle is in degrees, but we need radians const radians = angle * math.pi / 180; const gradientLine = (math.abs(math.sin(radians)) + math.abs(math.cos(radians))); const cathetus = fn => math.round(fn(radians - math.pi / 2) * gradientLine / 2, 10); const x = cathetus(math.cos); const y = cathetus(math.sin);
+ 8 other calls in file
GitHub: ogneyar/LeidtogiServer
223 224 225 226 227 228 229 230 231 232
// continue // пропусти }else { let myArticle = "tor" + newProduct.article let newPrice = Math.round( newProduct.price * 100 ) /100 if (response !== `{<br />`) response += ",<br />" let yes = false old.forEach(oldProduct => {
+ 41 other calls in file
238 239 240 241 242 243 244 245 246
let length, array = [], string = "" length = await this.getLength() if (pol && pol == 1) length = Math.round(length / 2) if (pol && pol == 2) pol = Math.round(length / 2) + 1 if (! pol) pol = 1
+ 3 other calls in file
198 199 200 201 202 203 204 205 206 207 208
return curr_price * Math.exp(drift + randomShock); } function normSinv(prob) { // Compute the inverse of the CDF of the standard normal distribution return math.round(math.invCdf('normal', prob, {mu: 0, sigma: 1}), 4); } export default Stock;
+ 2 other calls in file
GitHub: ogneyar/AstElectro
161 162 163 164 165 166 167 168 169 170
// // continue // пропусти // }else { // let myArticle = "tor" + newProduct.article // let newPrice = Math.round( newProduct.price * 100 ) /100 // if (response !== `{<br />`) response += ",<br />" // let yes = false // old.forEach(oldProduct => {
+ 471 other calls in file
38 39 40 41 42 43 44 45 46 47
positionId: lastIndex + 1, name: "Доставка", quantity: { value: 1, measure: "штук" }, itemCode: "0001", tax: { taxType: 6 }, itemPrice: Math.round(body.deliverySum * 100) // перевод в копейки }] } let create = {
+ 311 other calls in file
GitHub: ogneyar/AstElectro
22 23 24 25 26 27 28 29 30 31
let article = one.article let name = one.name + " (" + article + ")" let url = translit(name) //+ "_" + article.replace("/", "_") let priceEuro = one.price let price = Math.round( (priceEuro * kursEuro) * 100 ) /100 let categoryUrl = one.category let category = await Category.findOne({ where: { url: categoryUrl } }) let categoryId = category.id || null // return { categoryUrl, category, categoryId }
+ 304 other calls in file
87 88 89 90 91 92 93 94 95 96
xlsx = await parseXlsx(size, [ "Артикул", "гр.", "д (мм)", "ш (мм)", "в (мм)" ]) let desired, article, weight, length, width, height, volume for(let number = 2; number <= 317; number++) { article = "rgk" + xlsx[number-2]["Артикул"] weight = Math.round((Number(xlsx[number-2]["гр."]) / 1000), 2) length = xlsx[number-2]["д (мм)"] width = xlsx[number-2]["ш (мм)"] height = xlsx[number-2]["в (мм)"] volume = Math.round(((Number(length) /1000) * (Number(width) /1000) * (Number(height) /1000)), 4)
+ 471 other calls in file
GitHub: ogneyar/AstElectro
304 305 306 307 308 309 310 311 312 313
if (response !== `{<br />`) response += ",<br />" let yes = false products.forEach(oldProduct => { if (oldProduct.article === `krs${newProduct.article}`) { let newPrice = newProduct.price newPrice = Math.round(newPrice * 100) / 100 if (newPrice != oldProduct.price) { response += `"krs${newProduct.article}": "Старая цена = ${oldProduct.price}, новая цена = ${newPrice}.` Product.update({ price: newPrice }, { where: { id: oldProduct.id } }
+ 156 other calls in file
mathjs.evaluate is the most popular function in mathjs (87200 examples)