10 examples of 'jquery parse float' in JavaScript

Every line of 'jquery parse 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
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}
65function float(str) {
66 if (!str) {
67 return 0;
68 }
69 return parseFloat(str, 10);
70}
8export function parseNumber(s) {
9 s = String(s).replace(/[^\d-.]/g, '').replace(/\.$/, '');
10 if (!s.match(NUMBER_RE)) { return null; }
11 return parseFloat(s, 10);
12}
25function parseFloat(v: any) {
26 if (v == undefined) {
27 return 0 / 0;
28 }
29
30 const num = tonumber(v);
31 if (num === null) {
32 return 0 / 0;
33 }
34
35 return num;
36}
162function parseDouble(str) {
163 // tolerant of commas and leading/trailing spaces
164 return parseFloat($.trim(str).replace(/,/g, ''))
165}
41function parse (str) {
42 var match = (/^((?:\d+)?\.?\d+) *(ms|seconds?|s|minutes?|m|hours?|h|days?|d|years?|y)?$/i).exec(str);
43 if (!match) {
44 return;
45 }
46 var n = parseFloat(match[1]);
47 var type = (match[2] || 'ms').toLowerCase();
48 switch (type) {
49 case 'years':
50 case 'year':
51 case 'y':
52 return n * y;
53 case 'days':
54 case 'day':
55 case 'd':
56 return n * d;
57 case 'hours':
58 case 'hour':
59 case 'h':
60 return n * h;
61 case 'minutes':
62 case 'minute':
63 case 'm':
64 return n * m;
65 case 'seconds':
66 case 'second':
67 case 's':
68 return n * s;
69 case 'ms':
70 return n;
71 default:
72 // No default case
73 }
74}
124function parseNumber(s: string): number {
125 const n = parseFloat(s);
126
127 if (isNaN(n)) {
128 throw new Error(`BillingClient: failed to parse '${s}' as a number`);
129 }
130
131 return n;
132}
36function toFloat (rvalue) {
37 return parseFloat(rvalue.toString().replace(/,/g, ''))
38}
14export function float([value]) {
15 return convertToFloat(value);
16}
12function makeNumber(v) {
13 return parseFloat(v.replace(/[$,]/g, ''), 10);
14}

Related snippets