On 28 Jul 2005 06:39:32 -0700,
nephish@xit.net declaimed the following
in comp.lang.python:
[color=blue]
>
> like this float(int(Var)/100)[/color]
First problem -- you are (or were, the operators have been
changing in Python) doing an integer/integer divide which (used to)
returns an integer, and integers don't have fractional parts; and /then/
you are telling it to convert this integer result to a float.
You need to convert the division to floats before performing it:
[color=blue][color=green][color=darkred]
>>> i = 50
>>> i/100 # integer/integer[/color][/color][/color]
0[color=blue][color=green][color=darkred]
>>> float(i)/100 # convert to float/integer[/color][/color][/color]
0.5[color=blue][color=green][color=darkred]
>>> i/100.0 # integer/float[/color][/color][/color]
0.5[color=blue][color=green][color=darkred]
>>>[/color][/color][/color]
[color=blue]
> 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
>[/color]
Display is formatting, separate from computational usage...
[color=blue][color=green][color=darkred]
>>> "%7.2f" % (i/100.0)[/color][/color][/color]
' 0.50'[color=blue][color=green][color=darkred]
>>> "%.2f" % (float(i)/100)[/color][/color][/color]
'0.50'
--[color=blue]
> ================================================== ============ <
>
wlfraed@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
>
wulfraed@dm.net | Bestiaria Support Staff <
> ================================================== ============ <
> Home Page: <http://www.dm.net/~wulfraed/> <
> Overflow Page: <http://wlfraed.home.netcom.com/> <[/color]