when I use string formula , the error is shown, I attached image for this error

The documentation says the following:
Strings are compared by their numerical value.
This behavior is kind of surprising I have to say.
@josdejong: Is there a string comparison function? So far I haven't found one, if there isn't it might be a good addition.
See https://github.com/josdejong/mathjs/issues/1051 for duplicate issue.
Comparisions between strings was removed in v4 because people doing "67" > "7" were getting a nasty suprise as strings were being compared lexically.
Mathjs now tries for convert to number before making the comparison.
@josdejong maybe mathjs should allow people to compare strings using == but not > etc. For instance in javascript you can compare objects using == but not using > or >=. This might address both types of problems people are having.
Clarified == vs ===.
On one hand I like the idea of having an === operator, since people using JavaScript might already be familiar with it, but on the other hand it might also be confusing.
But there needs to be a way to do string comparisons either way!
Sorry, I meant ==, I was suggesting using the existing equallity operator in mathjs to compare strings. I have edited my comment to make this clear.
@josdejong: Is there a string comparison function? So far I haven't found one, if there isn't it might be a good addition.
Yes, we should indeed add a function equalText or something like that. You can create such a function yourself with a one-liner: equalText(a, b) = (compareNatural(a, b) == 0).
@harrysarson Good idea. I expect though that changing == (math.equal) to also allow to compare strings with text has tricky cases. For example when the input contains a numeric value which cannot be parsed due to a typo, like "3,0E2" == "300", which will returns false instead of a parse error.
I like the idea of introducing a strictEqual function and === operator. This will allow comparing strings, and we can also use it to strictly compare numeric values, like make sure that both sides have the same numeric value and both are a number. But @FSMaxB you're right that this also makes things more complicated and confusing.
@josdejong you make a very good point about strings that are almost but not quite numbers.
I think it is much better for someone to try and compare two strings and get an error message than compare two nearly numbers and get false due to their typo and spend ages debugging for this.
I take back my string equality suggestion
It was a good suggestion, please keep them coming Harry :). It would have been the nicest solution but unfortunately there are some drawbacks.
I was thinking more about the strictEqual function and === operator. I think it will become quite confusing: in JavaScript strict equality on objects only returns true when having the same object instance. For example a BigNumber is from JavaScript perspective an object, so math.bignumber(2) === math.bignumber(2) returns false, but from mathjs perspective you may see a bignumber as an "atomic" unit like numbers and strings, and you may expect it to return true.
So maybe we should simply go for an equalText function.
The two different equals operators in js lead to a fair bit of cunfusion, I would definately argue for keeping things simple in mathjs and sticking to ==.
I much prefer the idea of an equalText function :) As a name suggestion: strcmp like in c.
I've thought about it a bit more and I agree with Harry that we should go for the simple solution.
Let's implement two simple functions compareText and equalText then.
I'm open to other naming of these functions. strcmp is of course well known from c and php for example, though I don't think there is much familiarity with it in the JavaScript world. I personally don't really like the name strcmp because it is quite cryptic. Also, so far the function names in mathjs mostly use full words and no abbreviations. But if people really want we can do it like that (and people can of course always create their own favorite alias for the function name).
Would compareText return -1,0 or 1 based on the comparison?
It would work similar to compare and compareNatural (and strcmp): returns 1 when the first argument is larger than the second, 0 when both are equal, and -1 when the first argument is smaller than the second.
In fact, thinking about it, we can simply use compareNatural for text comparison so an additional method compareText may be overkill. At least equalText is really needed.
console.log(math.compare(2, 1)) // 1
console.log(math.compare(1, 1)) // 0
console.log(math.compare(1, 2)) // -1
console.log(math.compareNatural('B', 'A')) // 1
console.log(math.compareNatural('A', 'A')) // 0
console.log(math.compareNatural('A', 'B')) // -1
I've implemented functions compareText and equalText, they are now available in v4.4.0. Enjoy :)
Most helpful comment
I've implemented functions
compareTextandequalText, they are now available inv4.4.0. Enjoy :)