I have some code where I can receive, depending on the case: a text , an integer (381) or a decimal (431.2).
They are all coming as a string.
How can I parse them to String, Int or Double as needed?
I have some code where I can receive, depending on the case: a text , an integer (381) or a decimal (431.2).
They are all coming as a string.
How can I parse them to String, Int or Double as needed?
Something like this should help:
Also, as @gidds said, another approach would be to extend the
Stringclass and then use the Elvis operator like this: