469,592 Members | 2,026 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,592 developers. It's quick & easy.

How can I convert binary float number into a decimal float number ?

How can I convert binary float number into a decimal float number ?
Aug 16 '10 #1

✓ answered by Dormilich

you do this as integer via parseInt() by passing the inputís radix (second parameter). (binary numbers usually ainít floats)

7 3871
Dormilich
8,652 Expert Mod 8TB
you do this as integer via parseInt() by passing the inputís radix (second parameter). (binary numbers usually ainít floats)
Aug 16 '10 #2
I am a beginner.So can you explain this that answer with an example.
Thanks
Aug 17 '10 #3
Dormilich
8,652 Expert Mod 8TB
in JavaScript there is exactly one number type: float (IEEE 774). that is, a binary number must be a string consisting of 0s and 1s. for string conversion you have 3 methods:
- Number() (the constructor for the Number objects)
- parseFloat() (parse a string into a float (obviously a decimal float))
- parseInt() (parse a string as integer into a float using the given radix)

thus if you have any number that’s not decimal, you have to apply parseInt(), as that’s the only function where you can set the radix.
Aug 17 '10 #4
Thank you sir I understood.
But please check is it possible to develope the script below, to convert binary float number in to decimal float number.


Expand|Select|Wrap|Line Numbers
  1. <html xmlns="http://www.w3.org/1999/xhtml"> 
  2.      <head></head>
  3.   <body>
  4.  <script type="text/javascript">
  5.    function ConvertToBinary(){
  6.         var numberValue = document.getElementById('NumberInput').value;
  7.        var decNumber = Number(numberValue);
  8.          var binaryNumber = decNumber.toString(2).toUpperCase();
  9.  
  10.          document.getElementById('Result').value = binaryNumber;
  11.        }
  12.        function ConvertToDec(){
  13.          var binaryNumber = document.getElementById('NumberInput').value;
  14.        var decNumber = parseInt(binaryNumber, 2);
  15.          document.getElementById('Result').value = decNumber;
  16.       }
  17.     </script>
  18.  
  19.      <div style="text-align:center">
  20.        Number: <input type="text" id="NumberInput"></input>
  21.        Result: <input type="text" id="Result"></input>
  22.       <br/>
  23.       <button onclick="ConvertToBinary();">Convert To Binary</button>
  24.       <button onclick="ConvertToDec();">Convert To Decimal</button>
  25.      <br />
  26.     </div>
  27.    </body>
  28.  </html>
Aug 17 '10 #5
Dormilich
8,652 Expert Mod 8TB
there’s one important thing you forgot:

© 2010 Frinavale


if you copy, copy right (pun intended)
Aug 17 '10 #6
Thank you sir I understood.
But please check is it possible to develope the script below, to convert binary float number in to decimal float number.



Expand|Select|Wrap|Line Numbers
  1.     <html xmlns="http://www.w3.org/1999/xhtml"> 
  2.          <head></head>
  3.      <body>
  4.   <script type="text/javascript">
  5.      function ConvertToBinary(){
  6.      var numberValue = document.getElementById('NumberInput').value;
  7.          var decNumber = Number(numberValue);
  8.           var binaryNumber = decNumber.toString(2).toUpperCase();
  9.  
  10.          document.getElementById('Result').value = binaryNumber;
  11.          }
  12.        function ConvertToDec(){
  13.         var binaryNumber = document.getElementById('NumberInput').value;
  14.         var decNumber = parseInt(binaryNumber, 2);
  15.          document.getElementById('Result').value = decNumber;
  16.        }
  17.     </script>
  18.  
  19.       <div style="text-align:center">
  20.         Number: <input type="text" id="NumberInput"></input>
  21.         Result: <input type="text" id="Result"></input>
  22.       <br/>
  23.        <button onclick="ConvertToBinary();">Convert To Binary</button>
  24.        <button onclick="ConvertToDec();">Convert To Decimal</button>
  25.        <br />
  26.      </div>
  27.    </body>
  28.   </html>
Aug 19 '10 #7
Dormilich
8,652 Expert Mod 8TB
I would assume Frinavale doesn’t publish code that’s not working.
Aug 19 '10 #8

Post your reply

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

Similar topics

reply views Thread by j2ee | last post: by
13 posts views Thread by Hako | last post: by
22 posts views Thread by xiao | last post: by
17 posts views Thread by D'Arcy J.M. Cain | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.