| | |
noob: What and when you would use Decimal vs Float Type
![]() |
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
and
Hope this helps.
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.000000000and
1.000000001Hope this helps.
![]() |
Similar Threads
- max int value? (C++)
- From Java beginner:Am I right with answers?:) (Java)
- Conversion (VB.NET)
- Irrational number data type (Computer Science)
- Help With Data-type Declaration Symbols (Pascal and Delphi)
- Help Me Please (C++)
- accessing private data members (C++)
Other Threads in the Python Forum
- Previous Thread: Capture stdin output from popen2
- Next Thread: KeyPress event with holding down the key
| Thread Tools | Search this Thread |
abrupt accessdenied ansi anti apache application approximation argv array assignment backend beginner binary bluetooth builtin calculator change character converter countpasswordentry curved customdialog dan08 dictionary edit exe file float format function gnu heads homework ideas inches input java keyboard lapse leftmouse library line lines linux list lists loop microphone mouse movingimageswithpygame mysqlquery newb number numbers numeric output parameters parsing path phonebook pointer prime programming py2exe pygame pyopengl python random recursion redirect remote reverse scrolledtext session software sprite sqlite statictext statistics string strings syntax terminal text thread threading time tlapse tuple twoup ubuntu unicode unit urllib urllib2 variable wordgame write wxpython xlib






