Hi Steven, On 2 January 2012 06:28, Steven D'Aprano <st...@pearwood.info> wrote: > That only applies to decimal values which can be represented using a fixed > number of decimal places. So 1/5 is fine, and is 0.2 exactly, but 1/3 is > not, since it would require an infinite number of decimal places.
Just a small nit pick with the above: 1/3 is however not a decimal number. The word decimal means "tenth part", decimal numbers are generally defined/understood as numbers that are expressible as decimal fractions, meaning numbers where the denominator is a power of 10 or is an exact "tenth part". Understood as such, decimal numbers are therefore obviously accurately representable by the Decimal class which is the whole point of calling the class "Decimal". To backtrack slightly, numbers like 1/3, 1/5 etc are in general called common or vulgar fractions, the only requirement being that they have an integer numerator and an integer non-zero denominator. The class of numbers representible like this is called rational numbers and the test for whether a number can be called rational is whether it can be written as such. The set of numbers we refer to as decimal numbers then, are a subset of rational numbers, the test for whether they can be called decimal being whether they can be written as a rational number with the additional requirement that the denominator be a power of ten. Addtionally, any rational number with a denominator of which the prime factors are 2 and 5 may therefore be rewritten as a decimal number, thus we know that 2/5 can also be accurately represented by a decimal number (since the prime factors of 5 is 5), as can 1/50 (since the prime factors of 50 are 2,5,5), but 1/3 can not, since 3 has only 3 as its prime factor (and not 2 or 5), and neither 1/24 (since the prime factors are 2,2,2,3). So an additional test for whether a given rational number can be accurately rewritten as a decimal (tenth part) number, is to inspect the prime factors of the denominator. If this consists solely of 2's and 5's it can be expressed as a decimal, if any other factors are present then it cannot be accurately expressed as a decimal. A happy and prosperous 2012 to all, Walter _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor