Re: [Tutor] How to correct decimal addition.

2014-01-26 Thread spir
On 01/26/2014 04:22 AM, Keith Winston wrote: On Sat, Jan 25, 2014 at 5:09 PM, Oscar Benjamin wrote: Perhaps it would be better though to point at this: round(D('0.123456'), 3) Decimal('0.123') I think you are right. I didn't even think of round(). I think we have confounded two issues in th

Re: [Tutor] How to correct decimal addition.

2014-01-25 Thread Keith Winston
On Sat, Jan 25, 2014 at 5:09 PM, Oscar Benjamin wrote: > Perhaps it would be better though to point at this: round(D('0.123456'), 3) > Decimal('0.123') I think you are right. I didn't even think of round(). I think we have confounded two issues in this thread, the internal representation/acc

Re: [Tutor] How to correct decimal addition.

2014-01-25 Thread spir
On 01/25/2014 10:38 PM, Keith Winston wrote: Also, just to be clear: I'd suggest floats because decimal requires importing a module and using the non-built-in features thereof The issue is not that much whether it's supported by builtins, in software, but by CPU's; which is not the case, so th

Re: [Tutor] How to correct decimal addition.

2014-01-25 Thread spir
On 01/25/2014 10:19 PM, Keith Winston wrote: On Sat, Jan 25, 2014 at 3:57 AM, spir wrote: Note: AFAIK most financial software use integers for this reason and to avoid (or control) rounding errors. I don't think this is true (no flame intended, hopefully you know I'm forever in your debt Deni

Re: [Tutor] How to correct decimal addition.

2014-01-25 Thread spir
On 01/25/2014 10:01 PM, Keith Winston wrote: On Sat, Jan 25, 2014 at 3:57 AM, spir wrote: .009 to the price, so that people do not have to type the full amount. Example, 3.49 /gallon would return 3.499 /gallon. This is what I have tried and the results of it. def gas_price(price): pri

Re: [Tutor] How to correct decimal addition.

2014-01-25 Thread Oscar Benjamin
On 25 January 2014 21:38, Keith Winston wrote: > > Also, just to be clear: I'd suggest floats because decimal requires > importing a module and using the non-built-in features thereof, Importing a module is not something to be afraid of. Python comes with loads of modules especially so you can im

Re: [Tutor] How to correct decimal addition.

2014-01-25 Thread Alan Gauld
On 25/01/14 21:19, Keith Winston wrote: On Sat, Jan 25, 2014 at 3:57 AM, spir wrote: Note: AFAIK most financial software use integers for this reason and to avoid (or control) rounding errors. I don't think this is true I can't speak for the general case but the only major financial app I'v

Re: [Tutor] How to correct decimal addition.

2014-01-25 Thread Keith Winston
Also, just to be clear: I'd suggest floats because decimal requires importing a module and using the non-built-in features thereof, especially if you're going to do something like decimal.getcontext().prec (even that doesn't set precision AFTER the decimal point... only total precision). My point b

Re: [Tutor] How to correct decimal addition.

2014-01-25 Thread Oscar Benjamin
On 25 January 2014 21:01, Keith Winston wrote: > > I think that you should probably do your math in floating point (why > get complicated? And you might need the accuracy, for hundredths of > dollars and interest) and then format the output to be what you want. > Watch out for rounding. It may no

Re: [Tutor] How to correct decimal addition.

2014-01-25 Thread Keith Winston
On Sat, Jan 25, 2014 at 3:57 AM, spir wrote: > Note: AFAIK most financial software use integers for this reason and to > avoid (or control) rounding errors. I don't think this is true (no flame intended, hopefully you know I'm forever in your debt Denis): there's a famous scam where insiders at a

Re: [Tutor] How to correct decimal addition.

2014-01-25 Thread Keith Winston
On Sat, Jan 25, 2014 at 3:57 AM, spir wrote: >> .009 to the price, so that people do not have to type the full amount. >> Example, 3.49 /gallon would return 3.499 /gallon. >> >> This is what I have tried and the results of it. >> >> def gas_price(price): >> price == raw_input("What is the pr

Re: [Tutor] How to correct decimal addition.

2014-01-25 Thread Oscar Benjamin
On 25 January 2014 08:57, spir wrote: > On 01/25/2014 09:46 AM, spir wrote: >> >> On 01/24/2014 06:57 PM, Leon S wrote: >>> >>> Here is what I'm trying to do, accept a price of gas, but I want to add >>> the >>> .009 to the price, so that people do not have to type the full amount. >>> Example,

Re: [Tutor] How to correct decimal addition.

2014-01-25 Thread spir
On 01/25/2014 09:46 AM, spir wrote: On 01/24/2014 06:57 PM, Leon S wrote: Here is what I'm trying to do, accept a price of gas, but I want to add the .009 to the price, so that people do not have to type the full amount. Example, 3.49 /gallon would return 3.499 /gallon. This is what I have tr

Re: [Tutor] How to correct decimal addition.

2014-01-25 Thread spir
On 01/24/2014 06:57 PM, Leon S wrote: Here is what I'm trying to do, accept a price of gas, but I want to add the .009 to the price, so that people do not have to type the full amount. Example, 3.49 /gallon would return 3.499 /gallon. This is what I have tried and the results of it. def gas_p

Re: [Tutor] How to correct decimal addition.

2014-01-24 Thread Dave Angel
Leon S Wrote in message: > _ (please post in plain text in this text mailing list. Html messes up formatting and causes some newsreaders grief.) .. Leon said: Here is what I'm trying to do, accept a price of gas, but I want to add the .009 to the price, so that people do n

Re: [Tutor] How to correct decimal addition.

2014-01-24 Thread wesley chun
hi leon, you made a good start and ran into something that i know doesn't seem right to you. however, before we attack the issue, there are some basic problems with the code you need to correct first. below are a few explanations and perhaps workarounds: 1. you're passing in price *and* asking

Re: [Tutor] How to correct decimal addition.

2014-01-24 Thread Norman Khine
maybe this would be of help https://stackoverflow.com/questions/455612/python-limiting-floats-to-two-decimal-points On Fri, Jan 24, 2014 at 5:57 PM, Leon S wrote: > Here is what I'm trying to do, accept a price of gas, but I want to add > the .009 to the price, so that people do not have to ty