Cast Data Type String to number

551 views
Skip to first unread message

Christopher Scott

unread,
Oct 13, 2016, 2:17:43 PM10/13/16
to Tasker
Surely there is an easy way to cast a variable stored as a string to a number. For example -

-----

Action 1: Read file [file contains the number 1, which is returned as text.] Set file content to %file_contents. Variable %file_contents always contains a single value.

Action 2: Set Variable %id_number to variable %file_contents. Toggle Do Maths to true (checked).

If %id_number is 1,

Action 3: do nothing

else if %id_number >1

Action 4: add 1 to variable %id_number

-----

At this point, Action 4 throws an error stating %id_number is not data type number.

I assume %id_number is text because it was read from a plain text file. If that is true, %id_number should be converted to data type number.

I looked at the action Variable Convert. However, this action does not include an option to convert data type text to data type number.

How do I achieve converting data type text to a number without writing Java code? Writing code to do this transformation seems like it should be unnecessary.

Robert Ryan

unread,
Oct 13, 2016, 3:01:19 PM10/13/16
to tas...@googlegroups.com

It might help to export and post the human readable description of the profile or task. See https://redd.it/50u0vz for instructions if needed.

What you wrote doesn't make much sense to me.

Rich D

unread,
Oct 13, 2016, 6:02:05 PM10/13/16
to Tasker Google Groups Post

> How do I achieve converting data type text to a number without writing Java code? Writing code to do this transformation seems like it should be unnecessary.
>
>

No converting necesary. If the only data in the variable are numbers Tasker will preform maths on it.  I believe the issue you are having is when you read it from a file there is sometimes a hidden character in the text string. It is end of line or end of file or something like that.
just do a action / variable / test variable / length to see if it is there.  Then do a variable section.

Christopher Scott

unread,
Oct 13, 2016, 6:31:40 PM10/13/16
to Tasker
Thanks, Rick. I'll give that a try.

Christopher Scott

unread,
Oct 13, 2016, 6:37:41 PM10/13/16
to Tasker
You are so right - your diagnosis is spot on. I had toggled Add Line without thinking about it, so an UTF-8 end of line character was sitting there waiting to be read back into a variable.

Thanks, Rich. It would have taken me a week to see that tree in the forest.

Reply all
Reply to author
Forward
0 new messages