This commit is contained in:
2019-12-11 20:55:26 +00:00
parent 79a84eba42
commit ba5c44bf59
2 changed files with 37 additions and 2 deletions

View File

@@ -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