10 examples of 'javascript string to float' in JavaScript

Every line of 'javascript string to 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
this disclaimer
41function stringToFloat(value) {
42 return parseFloat(value.replace(/[^0-9,]/g, '').replace(',', '.'));
43}
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

65function float(str) {
66 if (!str) {
67 return 0;
68 }
69 return parseFloat(str, 10);
70}
36function toFloat (rvalue) {
37 return parseFloat(rvalue.toString().replace(/,/g, ''))
38}
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}
23parseFloat() {
24 return new Value(this.response, 'Text of ' + this.name, parseFloat(this.toString()));
25}
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}
18function Float (value) {
19 return Number(value)
20}
14export function float([value]) {
15 return convertToFloat(value);
16}
3228function parseArrayToFloat( string ) {
3229
3230 return string.split( ',' ).map( function ( element ) {
3231
3232 return parseFloat( element );
3233
3234 } );
3235
3236}
39export function ToInt(stringOrFloatVal) { return parseInt(stringOrFloatVal); }

Related snippets