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

Javascript question

P: 1
If i have a number num = 123.456
How could i separate them into num1 = 123 / num2 = 456
Nov 13 '06 #1
Share this Question
Share on Google+
1 Reply


100+
P: 141
hi,

i think this is the solution for ur problem

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. <html>
  4. <head>
  5.     <title>Untitled Page</title>
  6.     <script type="text/javascript">
  7.     function splitnum()
  8.     {
  9.     var str=document.form1.text1.value;
  10.     index=str.indexOf(".");
  11.     if(index!=-1)
  12.     {
  13.     num1=str.substring(0,index);
  14.     num2=str.substring(index+1,str.length);
  15.     }
  16.     else{ num1=str;num2=0;}
  17.  
  18.     alert(num1);
  19.     alert(num2);
  20.     }
  21.     </script>
  22. </head>
  23. <body>
  24. <form name="form1">
  25. <input type="text" onblur="splitnum()" name="text1" />
  26. </form>
  27. </body>
  28. </html>
  29.  
  30.  
  31.  










If i have a number num = 123.456
How could i separate them into num1 = 123 / num2 = 456
Nov 13 '06 #2

Post your reply

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