Decimals

Tim Roberts timr at probo.com
Wed Jun 14 09:08:47 CEST 2006


"Tgone" <bapolis at gmail.com> wrote:
>Sybren Stuvel wrote:
>> Tgone enlightened us with:
>> > Sorry, when I print out the variable it displays as '15.0'. The
>> > price is '15.00' in the database though.
>>
>> That's the same thing, isn't it? 15.0 == 15.000000000
>
>Yes, they're both mathematically the same. I never said they weren't...
>
>> > Here's my code:
>> >
>> > product = Product.get(2)
>> > print product.price # 15.0
>>
>> Try string formatting:
>>
>> print '%.2f' % product.price
>
>That works. I expected Python to display the data exactly as it is in
>the database, like most languages.

"Like most languages?"  Name one.

C and C++ certainly will not display this with two decimal places, unless
you print it out with a %.2f format.

DECIMAL is an SQL thing.  Unless the language has a native decimal type, it
cannot possibly know how to display it in the same format as your SQL.
-- 
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.



More information about the Python-list mailing list