Jump to content

~mr_wizard~

New Members
  • Posts

    2
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

~mr_wizard~'s Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thank you for the reply and yes I discovered and read alot about the floating point. After talking with my brother who is a Software / Robotics Engineer for NASA, he basically explained that a computer will run out the decimal places. that is truly never a zero. Makes sense. But as a way to combat this issue, they use a double accuracy check in a matter of speaking. Basically, in my case, I want to display 2 decimal places. So if I store the integer in the database as 4 decimals, ( DECIMAL(10,4) ) and process them troughout the script that way, simply use round($foo, 4); and then at the last minute before display take it to 2 decimals then it will stay pretty accurate. When looping thru just a few records and adding them together, not much will change. But if, like in my case, your looping thru 10's of thousands of records then by the time it hits the end of the loop, you will end up with extra digits that you never placed. Anyway, most of you probably already know that but I thought I would reply so that someone else who didn't would maybe have a better understanding.
  2. I am doing some simple math and it is spitting out very odd results. //First Loop to get the values $get_values = mysql_query("SELECT * FROM table"); while($values = mysql_fetch_array)){ $value_one += $values[value_one]; $value_two += $values[value_two]; } $difference = $value_one - $value_two; echo"$value_one - $value_two = $difference; The database field types are DECIMAL(10,2). The output of the individual values is echoing the correct 0.00 format but after it loops for awhile the difference seems to come out differently. and have close to 5 or 6 places after the decimal. if i echo the values as it is looping and adding them it seems to not be adding correctly either. What am I doing wrong?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.