Working with decimals part 2

Chris Angelico rosuav at gmail.com
Mon Aug 25 14:16:06 EDT 2014


On Tue, Aug 26, 2014 at 3:55 AM, Seymore4Head
<Seymore4Head at hotmail.invalid> wrote:
> For some reason, it is not working.  If I try to use row2 I get this
> error:
> http://i.imgur.com/FgeF9c9.jpg

Several meta-issues.

Firstly, your subject line talks about 'decimal' again. You're
actually working with floats; Python has a quite separate decimal
module, and it's not what you're doing here. It's confusing for those
of us who know that you're actually working in binary floating point
:)

Secondly: An image is a really bad way to capture an error message.
Instead of saying "it is not working" and uploading a screenshot to
imgur, just copy and paste the exception into the body of the email.

Thirdly: If you're working iteratively, keep the files as simple as
possible, and if you can do this as one-liners in Idle's interactive
mode, that's probably the easiest way to show us what's happening.
Don't bury all of them in together into a single program.

As to your actual issue... it's a little unclear, because the system's
interpretation of what you've written is completely different from
yours - due to one misplaced bracket.

>>> str(format(number), ',.2f'))

You want to format the number .2f, not str the formatted number .2f. I
think you can figure it out from there :)

ChrisA



More information about the Python-list mailing list