[Tutor] How to ignore some decimal values?
Danny Yoo
dyoo@hkn.eecs.berkeley.edu
Thu, 17 Jan 2002 18:55:42 -0800 (PST)
On Wed, 16 Jan 2002, Titu Kim wrote:
> Do someone has any idea on keeping the floor value
> of a fixed decimal point n? For instance:
> a=12.3451
> b=0.5699
> c=0.0
>
> How can i make a,b, and c become float values as
> a=12.34
> b=0.56
> c=0.00
> if my n=2. If n=3
> a=12.345
> b=0.569
> c=0.000
By the way, there's a module called "FixedPoint" written by Tim Peters.
You can find it here:
ftp://python.org/pub/python/contrib-09-Dec-1999/DataStructures/FixedPoint.py.Z
If you're doing math that involves keeping decimal places, FixedPoint may
be useful for you. For example:
###
>>> import FixedPoint
>>> a = FixedPoint.FixedPoint("12.3451", 2)
>>> a
FixedPoint('12.35', 2)
>>> b = .75
>>> a * b
FixedPoint('9.26', 2)
###
Good luck to you.