Every line of 'javascript truncate float' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.
21 function truncate(num, precision) { 22 precision = (precision !== undefined) ? precision : 6; 23 const factor = Math.pow(10, precision); 24 return Math.round(num * factor) / factor; 25 }
114 function floatToFix(f) 115 { 116 return parseInt(f*(1<<16)); 117 }
22 function roundFloat(val) { 23 return Math.floor(val * 100) / 100; 24 }
272 export function truncate(number) { 273 return Math.round(number * 100000) / 100000; 274 }
237 function roundToFloat(float) { 238 r[0] = float; 239 var float_r = r[0]; 240 return float_r; 241 }
18 function Float (value) { 19 return Number(value) 20 }
19 function filterFloat(value) { 20 if(/^(\-|\+)?([0-9]+(\.[0-9]+)?|Infinity)$/ 21 .test(value)) 22 return Number(value); 23 return NaN; 24 }
75 function float(val) { 76 /* jshint eqnull: true */ 77 if (val == null) { 78 return null; 79 } 80 var r = parseFloat(val); 81 return isNaN(r) ? val : r; 82 }
9 function float_precision(float_value, precision) { 10 float_value = parseFloat(float_value); 11 if (isNaN(float_value)) { 12 return parseFloat('0').toFixed(precision); 13 } 14 else { 15 var power = Math.pow(10, precision); 16 float_value = (Math.round(float_value * power) / power).toFixed(precision); 17 return float_value.toString(); 18 } 19 }