In article <595969e7-354f-456d-82b5-6aeafbabe...@d8g2000yqf.googlegroups.com>,
Mark Dickinson wrote:
>
> - If you *really* need a number that represents the *exact* value
>34.52, then use the decimal module, or perhaps consider using a simple
>home-brewed fixed-point representation.
Don't use
On 13 août, 17:43, Mark Dickinson wrote:
> On Aug 13, 3:03 pm, jmfauth wrote:
>
>
>
> > A quick question.
>
> > I understand how to get these numbers
>
> > 34.5231263880373081783294677734375
>
> > and
>
> > 47 (from 2**47)
>
> > and the sign.
>
> > with the decimal module, but I f
On Aug 13, 3:03 pm, jmfauth wrote:
> A quick question.
>
> I understand how to get these numbers
>
> 34.5231263880373081783294677734375
>
> and
>
> 47 (from 2**47)
>
> and the sign.
>
> with the decimal module, but I fail to find this one
>
> 4858258098025923
>
> Possible?
See the
A quick question.
I understand how to get these numbers
34.5231263880373081783294677734375
and
47 (from 2**47)
and the sign.
with the decimal module, but I fail to find this one
4858258098025923
Possible?
--
http://mail.python.org/mailman/listinfo/python-list
On Aug 12, 9:43 pm, Bradley Hintze
wrote:
> Hi all.
>
> Is there a way I can keep my floating point number as I typed it? For
> example, I want 34.52 to be 34.52 and NOT 34.520002.
Nitpick: unless you're on very unusual hardware, you're missing some
zeros here. On my machine, under Python 2.
On Thu, 12 Aug 2010 18:19:40 -0700, Benjamin Kaplan wrote:
> But that's not keeping the number the way it was typed. It's just not
> showing you the exact approximation.
Nor is 34.523 showing you the "exact approximation".
The closest "double" to 34.52 is 4858258098025923 / 2**47, wh
In article
,
Benjamin Kaplan wrote:
> > Well, it is a *bit* of a Python issue since, as others have pointed out,
> > Python's behavior has changed due to the implementation of Gay's
> > rounding algorithm in 3.1 and also in 2.7:
> >
> > $ python2.6 -c 'print(repr(34.52))'
> > 34.523
On Thu, Aug 12, 2010 at 6:14 PM, Ned Deily wrote:
> In article ,
> Christian Heimes wrote:
>>> Is there a way I can keep my floating point number as I typed it? For
>>> example, I want 34.52 to be 34.52 and NOT 34.520002.
>> This isn't a Python issue. Python uses IEEE 754 [1] double precisio
In article ,
Christian Heimes wrote:
>> Is there a way I can keep my floating point number as I typed it? For
>> example, I want 34.52 to be 34.52 and NOT 34.520002.
> This isn't a Python issue. Python uses IEEE 754 [1] double precision
> floats like most other languages. 34.52 can't be stor
> Is there a way I can keep my floating point number as I typed it? For
> example, I want 34.52 to be 34.52 and NOT 34.520002.
This isn't a Python issue. Python uses IEEE 754 [1] double precision
floats like most other languages. 34.52 can't be stored in a float. The
next valid float is 34.520
On 2010-08-12, Grant Edwards wrote:
>> Here are the nitty-gritty details:
>>
>> http://docs.sun.com/source/806-3568/ncg_goldberg.html
>
> Here is a gentler intro:
>
> http://pyfaq.infogami.com/why-are-floating-point-calculations-so-inaccurate
And another good page:
http://docs.python.org/t
On Thu, Aug 12, 2010 at 1:43 PM, Bradley Hintze
wrote:
> Hi all.
>
> Is there a way I can keep my floating point number as I typed it? For
> example, I want 34.52 to be 34.52 and NOT 34.520002.
See also:
http://en.wikipedia.org/wiki/Floating_point#Representable_numbers.2C_conversion_and_ro
On Thursday 12 August 2010, it occurred to Bradley Hintze to exclaim:
> Hi all.
>
> Is there a way I can keep my floating point number as I typed it? For
> example, I want 34.52 to be 34.52 and NOT 34.520002.
The conversion from decimal to binary and vice versa is inexact -- but they're
the
On Aug 12, 2010, at 4:43 PM, Bradley Hintze wrote:
Hi all.
Is there a way I can keep my floating point number as I typed it? For
example, I want 34.52 to be 34.52 and NOT 34.520002.
Hi Bradley,
Use the Decimal type instead. It's not as convenient as float, but it
will give you a consis
On 2010-08-12, Grant Edwards wrote:
> On 2010-08-12, Bradley Hintze wrote:
>
>> Is there a way I can keep my floating point number as I typed it?
>
> No.
>
>> For example, I want 34.52 to be 34.52 and NOT 34.520002.
>
> You can't represent 34.52 using base-2 IEEE floating point (the HW
> floa
On 2010-08-12, Bradley Hintze wrote:
> Is there a way I can keep my floating point number as I typed it?
No.
> For example, I want 34.52 to be 34.52 and NOT 34.520002.
You can't represent 34.52 using base-2 IEEE floating point (the HW
floating point format used by pretty much all modern co
On 08/12/2010 01:43 PM, Bradley Hintze wrote:
Hi all.
Is there a way I can keep my floating point number as I typed it? For
example, I want 34.52 to be 34.52 and NOT 34.520002.
Is this a Python question?
The answer is both Yes and No. The binary floating point representation
of nu
Hi all.
Is there a way I can keep my floating point number as I typed it? For
example, I want 34.52 to be 34.52 and NOT 34.520002.
--
Bradley J. Hintze
Graduate Student
Duke University
School of Medicine
801-712-8799
--
http://mail.python.org/mailman/listinfo/python-list
"Tuvas" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>I would like to limit a floating variable to 4 signifigant digits, when
> running thorugh a str command. Ei,
>
>
> x=.13241414515
> y=str(x)+" something here"
>
> But somehow limiting that to 4 sign. digits. I know that if you us
Tuvas wrote:
> Wait, one more question. If the number is something like:
>
> 1.32042
>
> It is like
> "1.32 stuff"
>
> I would like it's size to remain constant. Any way around this?
s/%g/%f
>>> print "%.4f stuff" % 1.3241414515
1.3241 stuff
>>> print "%.4f stuff" % 1.32042
1.3204 stuff
>>>
On 2005-11-10, Dan Bishop <[EMAIL PROTECTED]> wrote:
> Grant Edwards wrote:
>> On 2005-11-09, Tuvas <[EMAIL PROTECTED]> wrote:
>>
>> > I would like to limit a floating variable to 4 signifigant digits, when
>> > running thorugh a str command.
>>
>> Sorry, that's not possible.
>
> Technically, it is
Grant Edwards wrote:
> On 2005-11-09, Tuvas <[EMAIL PROTECTED]> wrote:
>
> > I would like to limit a floating variable to 4 signifigant digits, when
> > running thorugh a str command.
>
> Sorry, that's not possible.
Technically, it is.
>>> class Float4(float):
...def __str__(self):
...
On 2005-11-09, Tuvas <[EMAIL PROTECTED]> wrote:
> Wait, one more question. If the number is something like:
>
> 1.32042
>
> It is like
> "1.32 stuff"
>
> I would like it's size to remain constant. Any way around this?
http://www.python.org/doc/current/lib/typesseq-strings.html#l2h-211
--
Grant E
"Tuvas" <[EMAIL PROTECTED]> wrote:
>I would like to limit a floating variable to 4 signifigant digits, when
> running thorugh a str command. Ei,
>
> x=.13241414515
> y=str(x)+" something here"
>
> But somehow limiting that to 4 sign. digits. I know that if you use the
> print statement, you can do
Wait, one more question. If the number is something like:
1.32042
It is like
"1.32 stuff"
I would like it's size to remain constant. Any way around this?
--
http://mail.python.org/mailman/listinfo/python-list
On 2005-11-09, Tuvas <[EMAIL PROTECTED]> wrote:
> I would like to limit a floating variable to 4 signifigant digits, when
> running thorugh a str command.
Sorry, that's not possible.
> x=.13241414515
> y=str(x)+" something here"
>
> But somehow limiting that to 4 sign. digits. I know that if
> y
Yep, I was thinking in C, not python. Thanks for the help!
--
http://mail.python.org/mailman/listinfo/python-list
I think you answered your own question. :)
x = 0.12345678
y = "%.4f something here" % x
On Wed, 2005-11-09 at 11:52 -0800, Tuvas wrote:
> I would like to limit a floating variable to 4 signifigant digits, when
> running thorugh a str command. Ei,
>
>
> x=.13241414515
> y=str(x)+" something here
Tuvas wrote:
> I would like to limit a floating variable to 4 signifigant digits, when
> running thorugh a str command. Ei,
>
>
> x=.13241414515
> y=str(x)+" something here"
>
> But somehow limiting that to 4 sign. digits. I know that if you use the
> print statement, you can do something like %
I would like to limit a floating variable to 4 signifigant digits, when
running thorugh a str command. Ei,
x=.13241414515
y=str(x)+" something here"
But somehow limiting that to 4 sign. digits. I know that if you use the
print statement, you can do something like %.4d, but how can I do this
with
30 matches
Mail list logo