9 examples of 'javascript truncate float' in JavaScript

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.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
21function truncate(num, precision) {
22 precision = (precision !== undefined) ? precision : 6;
23 const factor = Math.pow(10, precision);
24 return Math.round(num * factor) / factor;
25}
114function floatToFix(f)
115{
116 return parseInt(f*(1<<16));
117}
22function roundFloat(val) {
23 return Math.floor(val * 100) / 100;
24}
272export function truncate(number) {
273 return Math.round(number * 100000) / 100000;
274}
237function roundToFloat(float) {
238 r[0] = float;
239 var float_r = r[0];
240 return float_r;
241}
18function Float (value) {
19 return Number(value)
20}
19function filterFloat(value) {
20 if(/^(\-|\+)?([0-9]+(\.[0-9]+)?|Infinity)$/
21 .test(value))
22 return Number(value);
23 return NaN;
24}
75function 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}
9function 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}

Related snippets