Suppose a value is "floored" (floored in some arbitrary digit) when its displayed (7.785->7.7, 110.6->110). Let this floored value be called flooredTarget
. Suppose I have another number variable named toCheck
. How would I check if the significant digits of flooredTarget
and toCheck
are equal?
NOTE: the first parameter is flooredTarget
.
checkSignificant(7.7, 7.785); // true as 7.7 is common
checkSignificant(7.785, 7.8); // false as toCheck doesn't contain 7.785
Should I just check if toCheck.toString().beginsWith(flooredTarget.toString())
? Or is there some other better way (Assume any language)
2
Answers
You can use regexp
Converting to text is a performance killer there are other ways for example I see it like this in C++:
there is still a lot of room for improvement like making
align_to_exp
brunchless but In this form the code is more understandable.