9 examples of 'javascript float to integer' in JavaScript

Every line of 'javascript float to integer' 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
this disclaimer
39export function ToInt(stringOrFloatVal) { return parseInt(stringOrFloatVal); }
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

18function Float (value) {
19 return Number(value)
20}
73export function coerceToInteger(
74 num: number | string | undefined
75): number | undefined {
76 if (num === undefined) return undefined
77
78 const coerced = Number.parseInt(num.toString(), 10)
79 if (Number.isNaN(coerced)) return undefined
80
81 return coerced
82}
147function evaluateAsFloat(code) {
148 var variables = Object.create(null);
149 variables.e = Math.E;
150 variables.pi = Math.PI;
151
152 function evaluate(obj) {
153 switch (obj.type) {
154 case "number": return parseInt(obj.value);
155 case "name": return variables[obj.id] || 0;
156 case "+": return evaluate(obj.left) + evaluate(obj.right);
157 case "-": return evaluate(obj.left) - evaluate(obj.right);
158 case "*": return evaluate(obj.left) * evaluate(obj.right);
159 case "/": return evaluate(obj.left) / evaluate(obj.right);
160 }
161 }
162 return evaluate(parse(code));
163}
65function float(str) {
66 if (!str) {
67 return 0;
68 }
69 return parseFloat(str, 10);
70}
114function floatToFix(f)
115{
116 return parseInt(f*(1<<16));
117}
41function stringToFloat(value) {
42 return parseFloat(value.replace(/[^0-9,]/g, '').replace(',', '.'));
43}
29export function isFloat(n) {
30 return Number(n) === n && n % 1 !== 0;
31}
104function floatToInt_(sample, args) {
105 return parseInt(
106 sample > 0 ? sample * args.newMax : sample * args.newMin, 10);
107}

Related snippets