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