prepare recipe turns number/lettercombo to numeric

Solved!
Jurre
Level 5
prepare recipe turns number/lettercombo to numeric

Hi,

In prepare recipes, when coded values are split up, it can happen that you end up with values like "1d", "1f" or "2e6". Testing and processing these values might give unexpected results when column values are not read with some care, see attached screenshot : 

  • col_0 is given
  • test_0 tests the value col_0 if it's numeric  
  • col_1 concatenates the value of col_0 with "5"
  • test_1 tests the value of col_1 if it's numeric.   

1d and 1f-values get changed into something else because i did not read those values as string, it would not have happened if i had used concat(strval("col_0"),"5") as formula for col_1.  So a solution is available and note is taken to keep this in mind when splitting values. I just don't understand why this happens in the first place, can anyone comment on that ? 

isNumericisNumeric


Operating system used: Ubuntu 18.04 

0 Kudos
1 Solution
pmasiphelps
Dataiker

Hi,

 

The val() function evaluates the value of a column, flexibly registering the type in Java. You're correct to point out that strval() evaluates the column value only as a string. val() is more flexible.

 

Numeric characters followed by a singe "f" or "d", e.g. 1f, 1d, are special, in that Java indeed registers these as numbers of the float or decimal type.

 

In your examples, "1f" is first changed to "1.0" (decimal added because of float type), and "1d" is also changed to "1.0" for the same reason. Then, your subsequent step concatenates the "5" to "1.0" - hence "1.05".

 

Note that this only happens when numeric characters are followed by a single "f" or "d" at the end. Trailing "ff" and "dd", or single "f" or "d" mixed in the middle of numbers won't see the same behavior.

Screen Shot 2022-01-06 at 10.27.18 PM.png

Best,

Pat

 

View solution in original post

2 Replies
pmasiphelps
Dataiker

Hi,

 

The val() function evaluates the value of a column, flexibly registering the type in Java. You're correct to point out that strval() evaluates the column value only as a string. val() is more flexible.

 

Numeric characters followed by a singe "f" or "d", e.g. 1f, 1d, are special, in that Java indeed registers these as numbers of the float or decimal type.

 

In your examples, "1f" is first changed to "1.0" (decimal added because of float type), and "1d" is also changed to "1.0" for the same reason. Then, your subsequent step concatenates the "5" to "1.0" - hence "1.05".

 

Note that this only happens when numeric characters are followed by a single "f" or "d" at the end. Trailing "ff" and "dd", or single "f" or "d" mixed in the middle of numbers won't see the same behavior.

Screen Shot 2022-01-06 at 10.27.18 PM.png

Best,

Pat

 

Jurre
Level 5
Author

Thank you @pmasiphelps  !

This is one of those little things to keep in mind when referencing column-values.. I had some pretty strange results after splitting up and further processing of codified values (nitrogen storage locations, don't want to get those wrong) when i did that carelessly with just val() instead of strval(). 

Cheers!

Jurre

0 Kudos