noob: What and when you would use Decimal vs Float Type

Reply

Join Date: Jan 2007
Posts: 58
Reputation: jobs is an unknown quantity at this point 
Solved Threads: 0
jobs jobs is offline Offline
Junior Poster in Training

noob: What and when you would use Decimal vs Float Type

 
0
  #1
Nov 4th, 2007
What and when you would use Decimal vs Float Type?
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,951
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: noob: What and when you would use Decimal vs Float Type

 
1
  #2
Nov 4th, 2007
Float types are just the hardware's floating point data type. Usually this is an IEEE single (4-bytes), double (8-bytes), or extended (10-bytes).

The problem with these is that they approximate numbers. Hence, they are not very exact. They lack precision and they are susceptible to the influences binary arithmetic.

The python decimal module gives a floating point class called Decimal which stores a number exactly. The tradeoff is that it is not as fast to use as a float. In most cases it is not so important to be so exact, so the float works just fine and there is no need to use Decimal.

However, in scientific computing exactness is often very important, so the Decimal type is very handy whenever it makes a difference between, say
1.000000000
and
1.000000001

Hope this helps.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC