0

I know how to convert a string to a number (parseInt, parseFloat, Math., + Number() etc.).

But this all doesn't work in a PODIO calculation field with a string from a PODIO text field (single line and multi line, and also not from a text type calculation field). Text in textfield: 123

var str = @textfield;
Number(str)  

Also when I tried with parseInt(str) etc. result is always the error msg.: Not a valid number.

It works e.g when str = "123", but not when I want to use the token @textfield. It works also when str is a category field token (and categorie is 123).

Any suggestion how I can convert a string to a number using a @textfield token?

TIA Rainer

3 Answers3

0

The most likely explanation is that you don't check whether @textfield is an empty string. E.g. parseInt('', 10); will result in NaN

  • No, @textfield is not empty. Text is "123", `@textfield.length` = 3, `typeof @textfield` = string , type of calculation field = number. When I use @textfield in a calcultion field = text type I get 123. – Rainer Grabowski Mar 30 '15 at 15:56
0

You just use @Email Text in the calculation field.

Mûhámmàd Yäsår K
  • 1,492
  • 11
  • 24
0

Finally found this! you need to add || 0 at the end of the code line with the conversion. Then the number will be accepted in PODIO calc. field. ex.

var x='123.48';

y=Number(x);// result is not a valid number

var x='123.48';

y=Number(x) || 0;// this works

Thought I'd save someone else the time I spent hunting this one down.....whew!

Asier Gomez
  • 6,034
  • 18
  • 52
  • 105
Daimo
  • 1
  • 1