Re: easy float question just eludes me




<nephish@xxxxxxx> wrote in message
news:1122557972.833617.157360@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Hullo all !
>
> i have a real easy one here that isn't in my book.
> i have a int number that i want to divide by 100 and display to two
> decimal places.
>
> like this float(int(Var)/100)

At present, int/int truncates, so this won't do what you want. Use
int/100.0 to get float you want. For output, use % formating operator with
f specification.

>>> '%7.2f' % (50/100.0)
' 0.50'

Terry J. Reedy



.



Relevant Pages

  • Re: easy float question just eludes me
    ... i have a real easy one here that isn't in my book. ... i have a int number that i want to divide by 100 and display to two ... but i need it to display the .00 even if it does not have a .00 value like this if Var is 50, i need to display .50 instead of just .5 ...
    (comp.lang.python)
  • easy float question just eludes me
    ... i have a real easy one here that isn't in my book. ... i have a int number that i want to divide by 100 and display to two ... but i need it to display the .00 even if it does not have a .00 value ...
    (comp.lang.python)