Closed alemaninc closed 2 years ago
No, no such method exsists. But can't you use Decimal's static methods which will automatically convert strings to Decimals for you (obviously only do it on values thst are actually meant to be Decimals)?
I store all my variables in an object, so that I can load everything at once without having to add more code to the load() function for each variable that I add (the load function uses a loop so that new variables added by updates don't get removed), and having to store a list of Decimals defeats the point of having this loop. I'll probably just create this method myself in my local version.
Can't you use Decimal's static methods everywhere where you do math on Decimals? This way, all the variables can be loaded as strings and they will be converted to Decimals by break eternity itself when you pass them to the static methods.
Is there a function which can check if
new Decimal(x)
is a valid number? I'd like to be able to automate loading from localStorage without having to make a list of around 100 variables that need to be converted into a Decimal.Examples:
Decimal.valid("3.141592653589793" )
=true
Decimal.valid("(e^8)15")
=true
Decimal.valid(true)
=false
Decimal.valid([1,1,2,3,5,8])
=false
Decimal.valid("Mixed scientific")
=false