How to convert Text from a text field into number type in calculation field by javascript ?
There is an app has Text fields "revenue_text"(content is "223") and "cost_text"(content is "100"),I would like to get profit in a calculation field by code below:
but ,there are error messages :
1."the result is not a valid number "
2."invalid value 123.0(number):must be string"
what's wrong with it ?
My purpose is to get string from text field ,then turn it into number in calculation field .
It seems the calculation field is text type instead of number type which is wanted by me .
How can I make it ?
The script as follows:
var a=@revenue_text ;
var b=@cost_text;
var c= parseFloat(a);
var d= parseFloat(b)
var profit=c-d;
profit;
Best
-
Hi ,
I met the same situation as your instruction .That means it worked in some calculation fields ,but some fields don't work .
please refer the screen shot :https://drive.google.com/file/d/0B3JEgK0GXrSSZ205Q2J4Wjl2clk/edit?usp=sharingI am not sure if it's the result from function :"parseFloat" ? but it does work in my previous fields.
Best
JianWen
-
Once a calculation field has been created its return type is locked. In your case it looks like you have created a calculation field that returns a string and now you're trying to return a number.
Remove your current calculation field and create a new one that returns a number from the start.
/Andreas
-
I've not been able to solve the issue. And yes, I'm sure the calculation field is a numbers field, since when I remove the string and the parsing everything works fine again.
Here's a screenshot: https://www.dropbox.com/s/54lz50j62taregu/Screenshot%202015-01-16%2022.55.14.png?dl=0
Best, Fritz
Please sign in to leave a comment.
Comments
11 comments