Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type conversion #27

Open
Questi1728 opened this issue Jun 6, 2024 · 4 comments
Open

Type conversion #27

Questi1728 opened this issue Jun 6, 2024 · 4 comments

Comments

@Questi1728
Copy link

Is there a way to convert string to to numericals? E.g. having a column of 01, 02, 03, .... as a result of a substring() calculation, DW correctly states perceived data type: numerical when hovering over the column header.
However, any calculation applied to the numbers will fail. There doesn't seem to be a type conversion, int(x) only accepts double, not strings?

@thsa
Copy link
Owner

thsa commented Jun 6, 2024

I cannot reproduce the issue using the table below. I tried "Add Calculated Values..." with 'int(Num)' and 'Num+2'. Both deliver the expected result. Can you provide an example that fails?

Type Num
a 01
b 02
c 03

@Questi1728
Copy link
Author

Apologies for the long silence here, didn't realise there was a reply ;-) I can see your solution working when I split the calculation into two steps:

  1. create NewColumn containing the substring
  2. performing a calculation on the NewColumn will change the type and perform calculation correctly

Where it doesn't work if both actions are wrapped into one statement, i.e. substring(StringColumn,2,4)*2 or int(substring(StringColumn,2,4))*2 both fail. Bit confusing!

I have attached an
Test.zip
example here.
Cheers,

@thsa
Copy link
Owner

thsa commented Aug 15, 2024

int() requires a number as input, while substring yields a string.

If you use substring to populate a column, DataWarrior evaluates it and offers it for further calculations as String and(!) as number, provided it can be interpreted as a number.

Now I realize that there is no conversion function from string to number, which I will add to the upcoming DataWarrior update... 'num()'

@thsa
Copy link
Owner

thsa commented Aug 15, 2024

num(substring(WellID,2,4))*2 will now work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants