469,592 Members | 2,026 Online

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

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
Udara chathuranga
14 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
Udara chathuranga
14 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">
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:

if you copy, copy right (pun intended)
Aug 17 '10 #6
Udara chathuranga
14 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">
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

 reply views Thread by j2ee | last post: by 13 posts views Thread by Hako | last post: by 2 posts views Thread by gokul | last post: by 2 posts views Thread by Tukeind | last post: by 9 posts views Thread by Leo jay | last post: by 1 post views Thread by sarbeswar | last post: by 3 posts views Thread by karthickkuchanur | last post: by 1 post views Thread by Swan | 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 reply views Thread by Marketing QM | last post: by reply views Thread by devgraph | last post: by reply views Thread by PitrL | last post: by reply views Thread by allessa | last post: by 1 post views Thread by Samuh | last post: by reply views Thread by hefaz | last post: by reply views Thread by billypeterson | last post: by 4 posts views Thread by guiromero | last post: by