Re: [Tutor] floats

2011-06-07 Thread Walter Prins
Hello Michael On 7 June 2011 21:10, Michael bridges wrote: > ok, will attempt to clarify. > i want to out put of two numbers [int or float or anything] to be x.xx not > x.x. > i want two numbers after the decimal not one. > > Alan's already given you exactly the correct answer. Have you tried h

Re: [Tutor] floats

2011-06-07 Thread Michael bridges
ok, will attempt to clarify. i want to out put of two numbers [int or float or anything] to be x.xx not x.x. i want two numbers after the decimal not one. --- On Tue, 6/7/11, Alan Gauld wrote: > From: Alan Gauld > Subject: Re: [Tutor] floats > To: tutor@python.org > Date: Tue

Re: [Tutor] floats

2011-06-07 Thread Alan Gauld
"Michael bridges" wrote i want to 10 / 1000 and get 0.01 not 0 if 1000 is made 1000.00 then 0.01 is printed but that gives 500 / 1000.00 is 0.5 not 0.50 can someone till me how to get a two decimal precision every time? You are confusing two different things.. The first case is that of inte

Re: [Tutor] floats

2011-06-06 Thread Christian Witts
On 2011/06/07 04:43 AM, Michael bridges wrote: i saw it somewhere, but where? i want to 10 / 1000 and get 0.01 not 0 if 1000 is made 1000.00 then 0.01 is printed but that gives 500 / 1000.00 is 0.5 not 0.50 i might be thinking C# not python. can someone till me how to get a two decimal precisi

Re: [Tutor] floats

2011-06-06 Thread Modulok
>> Can someone till me how to get a two decimal precision every time? print "%.2f" % (500/1000.0) # or... result = 500 / 1000.0 print "%.2f" % result Using 'new' style string formatting works too: print "{0:.2f}".format(500/1000.0) -Modulok- On 6/6/11, Michael bridges w

[Tutor] floats

2011-06-06 Thread Michael bridges
i saw it somewhere, but where? i want to 10 / 1000 and get 0.01 not 0 if 1000 is made 1000.00 then 0.01 is printed but that gives 500 / 1000.00 is 0.5 not 0.50 i might be thinking C# not python. can someone till me how to get a two decimal precision every time? _

Re: [Tutor] floats

2010-12-03 Thread Joel Goldstick
On Fri, Dec 3, 2010 at 1:52 PM, Christopher Spears wrote: > > I have a float variable that is very long. > > >>> float_a = 1.16667 > > However, I want to pass the value of float_a to float_b, but I want the > float to be accurate to two decimal points. > > >>> float_a = 1.16667 > >>> print "%.2f"

Re: [Tutor] floats

2010-12-03 Thread Alan Gauld
"Christopher Spears" wrote I have a float variable that is very long. float_a = 1.16667 Thats not really very long! However, I want to pass the value of float_a to float_b, but I want the float to be accurate to two decimal points. float_a = 1.16667 print "%.2f" % float_a 1.17 Round

Re: [Tutor] floats

2010-12-03 Thread Jerry Hill
On Fri, Dec 3, 2010 at 1:52 PM, Christopher Spears wrote: float_a = 1.16667 > > However, I want to pass the value of float_a to float_b, but I want the float > to be accurate to two decimal points. Use the built-in round() function, like this: >>> a = 1.16667 >>> print a 1.16667 >>> b = ro

Re: [Tutor] floats

2010-12-03 Thread Emile van Sebille
On 12/3/2010 10:52 AM Christopher Spears said... I have a float variable that is very long. float_a = 1.16667 However, I want to pass the value of float_a to float_b, but I want the float to be accurate to two decimal points. float_a = 1.16667 print "%.2f" % float_a 1.17 I tried the fol

Re: [Tutor] floats

2010-12-03 Thread Corey Richardson
On 12/3/2010 1:52 PM, Christopher Spears wrote: I have a float variable that is very long. float_a = 1.16667 However, I want to pass the value of float_a to float_b, but I want the float to be accurate to two decimal points. float_a = 1.16667 print "%.2f" % float_a 1.17 I tried the foll

Re: [Tutor] floats

2010-12-03 Thread Nitin Pawar
you have two options 1) either type cast like float_b = float(etcetc) 2) use round method which available inbuilt On Sat, Dec 4, 2010 at 12:22 AM, Christopher Spears wrote: > > I have a float variable that is very long. > > >>> float_a = 1.16667 > > However, I want to pass the value of float_a to

[Tutor] floats

2010-12-03 Thread Christopher Spears
I have a float variable that is very long. >>> float_a = 1.16667 However, I want to pass the value of float_a to float_b, but I want the float to be accurate to two decimal points. >>> float_a = 1.16667 >>> print "%.2f" % float_a 1.17 I tried the following: >>> float_b = "%.2f" % float_a >>>

Re: [Tutor] Floats and rounding down

2007-01-06 Thread Kent Johnson
Alan Gauld wrote: > "Toon Pieton" <[EMAIL PROTECTED]> wrote > >> Something like temp = '$' + str(round(x,2)) will make x = $1.537 >> read as >> $1.54. That's perfect. However, when x = 1.3, or x = 5.0, it will >> display >> just that: $1.3 or $5. I don't like that - I wan't 1.30 and 5.00, >> be

Re: [Tutor] Floats and rounding down

2007-01-06 Thread Alan Gauld
"Toon Pieton" <[EMAIL PROTECTED]> wrote > Something like temp = '$' + str(round(x,2)) will make x = $1.537 > read as > $1.54. That's perfect. However, when x = 1.3, or x = 5.0, it will > display > just that: $1.3 or $5. I don't like that - I wan't 1.30 and 5.00, > because > that looks much mor

[Tutor] Floats and rounding down

2007-01-06 Thread Toon Pieton
Hey all! A very simple question. I'm writing a simple program which does some calculations with money. I use floats for that, and yes, I know that floats arent as perfect as decimals, but its doesnt have to be a perfect program. I have, however, run into a "visual" problem. Something like temp