By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,144 Members | 872 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,144 IT Pros & Developers. It's quick & easy.

How to change integer to string

P: 2
Hi i have function in script. I did a small calculation in that function when i try to pass a value to in Field thet only passes integer value. But i need to pass both String and the integer value. So is it possible to convert from integer to string. Please let me know.

Thanks and Regards,
Kiran Nandamudi
Jan 17 '08 #1
Share this Question
Share on Google+
3 Replies


10K+
P: 13,264
Hi i have function in script. I did a small calculation in that function when i try to pass a value to in Field thet only passes integer value. But i need to pass both String and the integer value. So is it possible to convert from integer to string. Please let me know.

Thanks and Regards,
Kiran Nandamudi
Javascript's type checking system is such that you can pass an integer to a function that "expects" a string.
Jan 17 '08 #2

kaleeswaran
100+
P: 132
Hi i have function in script. I did a small calculation in that function when i try to pass a value to in Field thet only passes integer value. But i need to pass both String and the integer value. So is it possible to convert from integer to string. Please let me know.

Thanks and Regards,
Kiran Nandamudi
you can use:
String to Integer convertion
parseFloat(var)
Jan 18 '08 #3

gits
Expert Mod 5K+
P: 5,333
hi ...

you did get the answer in post #2 already, but let me explain that in more detail a little bit. JavaScript uses implicit type-casting dependent on what the OPERATION expects. so when you have a number-type and the operation expects a string javascript will cast the number to a string. in case you want to do it explicitly before then you may use:

Expand|Select|Wrap|Line Numbers
  1. var n = 1;
  2. var s = n.toString();
  3.  
  4. // now var s has a string '1' assigned :)
  5.  
note: sometimes the implict typecasting is a little bit tricky ... have a look at this:

Expand|Select|Wrap|Line Numbers
  1. // we compare an empty string to a number 0
  2. var val = '' == 0;
  3.  
  4. // val is now true since we compare different types and js
  5. // implcitly casts the types
  6. // so val will be true in the next examples too:
  7. val = '       ' == 0;
  8. val = '0' == 0;
  9. val = '0000000' == 0;
  10.  
  11. // in case you need to check the types too and avoid
  12. // the casting here you could use the identity-operator ===
  13. val = '0' === '';
  14.  
  15. // now val is false since the types are different
  16.  
kind regards
Jan 18 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.