10
0
mirror of https://github.com/LCPQ/QUESTDB_website.git synced 2024-12-25 13:53:48 +01:00
QUESTDB_website/static/js/numberUtils.js

23 lines
434 B
JavaScript
Raw Normal View History

2020-02-04 09:14:57 +01:00
class stringNumber{
2020-02-01 17:32:06 +01:00
constructor(value,printNaN=true) {
this.string=value
2020-02-01 17:32:06 +01:00
this.printNaN=printNaN
}
valueOf() {
2020-02-04 09:34:27 +01:00
return parseFloat(this.string)
}
toString(){
2020-02-04 09:14:57 +01:00
if (checkNumber(this.string) && this.printNaN) {
return this.string
2020-02-01 17:32:06 +01:00
} else {
return NaN.toString()
}
}
}
2020-02-04 09:14:57 +01:00
function checkNumber(string) {
try {
2020-02-02 15:35:21 +01:00
return !Number.isNaN(parseFloat(string))
} catch (error) {
return false
}
}