I tried this code using Column expression
abs(removeChars(removeChars(column(“Product Amount”)),","))
No error when I click evaluate, but when I execute the node
Error Message: ERROR Column Expressions 0:85 Execute failed: (“NullPointerException”): null
There is a node called -string to number- which can do this if the numbers are correctly written:
Otherwise, you would need anyway to correct their syntax. For instance, here the “150.00-” should be change to “150.00” before applying this node. Unfortunately you would need first to gather all the possible “wrong syntax” cases, treat them beforehand and then apply the -string to number- node.
I your post, the minus appears after the “150.00” as “150.00-”. Is this really the case in your KNIME table ? If so then it is normal that it fails. Could you please do a snapshot of your table to show us how the data looks in a KNIME table ? It would help us to understand what is going on
It’s RegEx substitution. I only learned that this exists last week.
We want to match any string followed by a "-". Everything except the "-" should be kept, so we put the “any string” into the round brackets. In the replacement, we use our variable ($1), with an additional "-" on the left side. Strings that don’t match are not changed.
. matches any character
* zero, one, or multiple occurences of the preceeding character
.* matches any string
() to use something as variable. variables are denoted with a $ followed by the variable number
Hi @seanmanzanilla , on top of what you have learned from @aworker 's and @Thyme 's posts, I hope you understood what the issue was.
Basically the String to Number converts the type from String to Number, but the string being converted has to be a valid number. “150.00-” and “1,000.00-” were not valid numbers. So Knime did not know what to convert them to, hence why you get a missing value (red ?) instead. On the other"-150.00" and “-1,000.00” are valid numbers.
One confusion was that you mentioned this:
This meant that the real value was -150.00, and “150.00-” was just a display thing (and that is why @aworker had said there should not be any problem), or so we thought. I’m not sure what was the deal with these numbers as clearly they did not seem to be -150.00 or -1,000.00 since Knime did not convert them.
That is also why your abs() function did not work.
This is because Evaluate button only evaluates the first row. Had you had “150.00-” in the first row, Evaluate would have failed.