small inaccuracies


Posted on 16th Feb 2014 07:03 pm by admin

I have this code to convert fractional base 10 into base 2:

while($num > 0)
{
echo "<tr><td>". $num." * 2 = </td><td>". $num*2 ."</td></tr>";
$num= $num*2;
if($num>= 1)
{ $num-= 1; $bin .= "1"; }
else
{ $bin .= "0"; }
}

anyway, stuff gets off, example:

Quote0.7 * 2 = 1.4
0.4 * 2 = 0.8
0.8 * 2 = 1.6
0.6 * 2 = 1.2
0.2 * 2 = 0.4
0.4 * 2 = 0.8
0.8 * 2 = 1.6
0.6 * 2 = 1.2
0.2 * 2 = 0.4
0.4 * 2 = 0.8
0.8 * 2 = 1.6
0.6 * 2 = 1.2
0.2 * 2 = 0.4
0.4 * 2 = 0.799999999999
0.799999999999 * 2 = 1.6
0.599999999999 * 2 = 1.2
0.199999999997 * 2 = 0.399999999994
0.399999999994 * 2 = 0.799999999988
0.799999999988 * 2 = 1.59999999998
0.599999999977 * 2 = 1.19999999995
0.199999999953 * 2 = 0.399999999907
0.399999999907 * 2 = 0.799999999814
0.799999999814 * 2 = 1.59999999963
0.599999999627 * 2 = 1.19999999925
0.199999999255 * 2 = 0.39999999851
0.39999999851 * 2 = 0.79999999702
0.79999999702 * 2 = 1.59999999404
0.59999999404 * 2 = 1.19999998808
0.199999988079 * 2 = 0.399999976158
0.399999976158 * 2 = 0.799999952316
0.799999952316 * 2 = 1.59999990463
0.599999904633 * 2 = 1.19999980927
0.199999809265 * 2 = 0.39999961853
0.39999961853 * 2 = 0.799999237061
0.799999237061 * 2 = 1.59999847412
0.599998474121 * 2 = 1.19999694824
0.199996948242 * 2 = 0.399993896484
0.399993896484 * 2 = 0.799987792969
0.799987792969 * 2 = 1.59997558594
0.599975585938 * 2 = 1.19995117188
0.199951171875 * 2 = 0.39990234375
0.39990234375 * 2 = 0.7998046875
0.7998046875 * 2 = 1.599609375
0.599609375 * 2 = 1.19921875
0.19921875 * 2 = 0.3984375
0.3984375 * 2 = 0.796875
0.796875 * 2 = 1.59375
0.59375 * 2 = 1.1875
0.1875 * 2 = 0.375
0.375 * 2 = 0.75
0.75 * 2 = 1.5
0.5 * 2 = 1
obviously, 0.4 * 2 does not equal 0.799999999999

how can i fix these inaccuracies?

No comments posted yet

Your Answer:

Login to answer
249 Like 9 Dislike
Previous forums Next forums
Other forums

try catch error
I have been trying try catch but, I can't get it to work. The code opens a non existing file called

utl_file open error
i have file in the unix path

Path /popdev01/pop/popdevb/tfi/

File name

Help Ordering Arrays
Hi, I have 3 arrays as shown below.

Code: $users = $this->get_latest_users();
$flir

ECC6 - Single sign-on
We are in the process of upgrading to ECC 6 which will support single sign on with user passwords al

How to form a xml form table with a single sql statement..?
Hi everyone,
I don't know if this is going to be a duplicate thread but i couldn't

php - xml what is the best way to do this.
IN essence I want to have a script calling the info from the database.. I have no problem thus far,

I need help on this PHP code
Hi everybody, I made some kind of mistake while editing the code below. As you see, at the 3 row my

Splitting Attributes
SQL> SELECT I_NAME, substr(I_NAME,1,instr(I_NAME,'O')) "First part",

substr(I_NAME, IN

Get word number x from string?
How can I use a function to loop through a string, and "have a look at" every word in the

what are '%S%', '%E%'
for example when i see Code: [Select]printf("Hello %srn", $name);
what does %s means

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash