[Edu-sig] handling money and floats with beginners
engelbert.gruber@ssg.co.at
engelbert.gruber@ssg.co.at
Thu, 3 Oct 2002 10:15:11 +0200 (CEST)
On Wed, 2 Oct 2002, Tim Wilson wrote:
> Hi everyone,
>
> I'm struggling a bit with explaining how important it is to handle
> floating point numbers correctly when doing calculations with money. My
> latest assignment (http://isd197.org/sibley/cs/icp/loancalc_html)
> involves calculating and printing a load payment schedule and I want my
> students to do things "the right way."
>
> My assignment instructions include a link to the Floating Point
> Arithmetic section of the python tutorial, but it's not quite enough.
>
> Does anyone have any code snippets that illustrate the problem clearly
> and are understandable by novices? My instructions say that the simplest
> approach is to do money-related calculations in pennies. Is that really
> the best approach for beginners? I didn't address this issue very well
> last year and I'd like to do a better job this time around.
1. since switching to euros some software must cope with with 1/100 cent.
2. ::
>>> r=10e+15
>>> "%20f" % r
'10000000000000000.000000'
>>> r+=1
>>> "%20f" % r
'10000000000000000.000000'
# incrementing by one is not possible
>>> r+=100
>>> "%20f" % r
'10000000000000100.000000'
>>> r+=1
>>> "%20f" % r
'10000000000000100.000000'
>>> r+=2
>>> "%20f" % r
'10000000000000102.000000'
# by two works
3. use mpz or as in the old days bcd-coding
4. in my school days we had to do calculations on date::
19871093 * 2 = 39742186
39742186 * 3 = 119226558
119226558 * 4 = 476906232
476906232 / 2 = 238453116
238453116 / 3 = 79484372
79484372 / 4 = 19871093
but going up to 10. now my son had the same kind of calcualtions
but going up to 13, which exceeded the calcualtors precision.
cheers
--
BINGO: professionally create virtual services
--- Engelbert Gruber -------+
SSG Fintl,Gruber,Lassnig /
A6410 Telfs Untermarkt 9 /
Tel. ++43-5262-64727 ----+