[Tutor] Decimal truncation, rounding etc.
Joe Cox
jgcox39 at highstream.net
Thu Oct 26 04:43:01 CEST 2006
Yes, I made a typo in the quantize. You are correct I am not able to read
and parse the text file properly?
I just face that IDE screen and it's all white. I am lost.
-----Original Message-----
From: Jason Massey [mailto:jason.massey at gmail.com]
Sent: Wednesday, October 25, 2006 4:25 PM
To: jgcox39 at highstream.net
Cc: tutor
Subject: Re: [Tutor] Decimal truncation, rounding etc.
More specifically, Joe, where and what types of errors are you getting?
When I type in your example exactly as above I get the following:
>>>from decimal import *
>>>
Decimal('7.0000').quantize(Decimal('1.000'),rounding=decimal.ROUND_DOWN)
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
NameError: name 'decimal' is not defined
That error appears because you've imported all of the decimal functions
into the global namespace and you're trying to reference a value in the
decimal namespace. In your example it'd have to look like this to work:
>>>Decimal('7.0000').quantize(Decimal('1.000'),rounding=ROUND_DOWN) #note
the lack of decimal in front of ROUND_DOWN
Decimal("7.000")
Or is the problem that you're not able to read and parse the text file
properly?
On 10/25/06, Joe Cox <jgcox39 at highstream.net> wrote:
My next project is to read a doc file and do some number editing.
I can alter numbers in the Interactive Shell OK:
import math
print round(7.12345,4)
7.1234
from decimal import*
Decimal('7.00000').quantize(Decimal('1.000'),rounding =
decimal.ROUND_DOWN)
Decimal("7.0000")
But when I go in to IDLE, I just don't seem to be able to make this
work.
A typical line of code for me to read and edit will look like:
G01 G91 X7.12345 Y7.0000 Z-0.0086
The underlines is what I need to edit, as above.
I must not understand something fundamental.
Joe Cox
513-293-4830
_______________________________________________
Tutor maillist - Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20061025/0772c7b2/attachment.html
More information about the Tutor
mailing list