This commit is contained in:
@@ -118,6 +118,35 @@ export default {
|
||||
default:
|
||||
return Boolean(string);
|
||||
}
|
||||
}, ///////////////////////////////
|
||||
// CONVERT STRING TO FLOAT
|
||||
// https://stackoverflow.com/a/9409894/8939
|
||||
//
|
||||
stringToFloat: function(string) {
|
||||
//null or empty then zero
|
||||
if (!string) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
//A number already then parse and return
|
||||
if (window.$gz._.isNumber(string)) {
|
||||
if (string === NaN) {
|
||||
return 0;
|
||||
}
|
||||
return parseFloat(string);
|
||||
}
|
||||
|
||||
//Not a string at all?
|
||||
if (!window.$gz._.isString(string)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
var ret = parseFloat(string.replace(/[^\d.-]/g, ""));
|
||||
if (ret == NaN) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
//new functions above here
|
||||
|
||||
Reference in New Issue
Block a user