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
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
"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
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
>> 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
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?
_
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"
"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
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
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
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
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
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
>>>
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
"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
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
16 matches
Mail list logo