set decimal place
Goh S H
python_only at yahoo.com
Wed Dec 26 04:09:47 EST 2001
OR use built-in function round if you're expecting float instead of string
Goh S H
David Lees <debl2nononospammywhammy at bellatlantic.net> wrote in message news:<3C292938.ED322C60 at bellatlantic.net>...
> >>> print '%8.1f' % (17.0/4)
> 4.3
> >>> print '%8.4f' % (10.0/4)
> 2.5000
> >>> print '%8.2f' % (20.0/7)
> 2.86
> >>> print '%8.5f' % (20.0/7)
> 2.85714
>
> David Lees
>
>
> kwsiew at tm.net.my wrote:
> >
> > is there a way(or any function) to set decimal place in python(to any
> > decimal place I want)
> > example :
> > 1)17.0/4 = 4.25 (but I want it to be 4.3)
> > 2)10.0/3 = 3.3333333333333335 (I want 3.3333 - 4 decimal place)
> > 3) 20.0/7 = 2.8571428571428572( I want 2.86 or 2.85714)
> >
> > thank you
> > rgds,
> > SKW
More information about the Python-list
mailing list