[Tutor] integers and float
MIG
max_ig@yahoo.com
Fri, 19 Jul 2002 10:29:11 -0700 (PDT)
Greg,
Thank you for your comments about formats. I'll try it.
I haven't thought on the rounding because the code only uses cents (two
digits). But you gave me a good point for cases such as sale tax.
Thank you,
Max
--- Gregor Lingl <glingl@aon.at> wrote:
> I didn't recognize, that your expression doesn't work correctly,
>
> 1.) because the parentheses are not balanced
>
> >
> >str(float(int((Variable_for_money)*100)/100
> >
>
> so it should read (I presume)
>
> str(float(int((Variable_for_money)*100))/100)
>
> but 2.) it doesn't round properly:
>
> >>> Variable_for_money=15.239
> >>> Variable_for_money
> 15.239000000000001
> >>> str(float(int((Variable_for_money)*100))/100)
> '15.23'
>
> And this comes so:
>
> >>> Variable_for_money*100
> 1523.9000000000001
> >>> int(Variable_for_money*100)
> 1523
> >>> float(int(Variable_for_money*100))
> 1523.0
> >>> float(int(Variable_for_money*100))/100
> 15.23
> >>> str(float(int(Variable_for_money*100))/100)
> '15.23'
> >>>
>
> Gregor
>
>
__________________________________________________
Do You Yahoo!?
Yahoo! Autos - Get free new car price quotes
http://autos.yahoo.com