- Jun 6, 2020
- 11,517
- 4,383
If the title of
this snippet in any way intrigues you then here is the routine which did that conversion.
You are, however, warned that however intriguing it might be it is all but totally useless .....
Conversion of decimal numbers to neat integer fractions is something you may have learned at school. The basic process is easy. Given 3.65 we just push the dot two places to the right, which means multiplying by 100, then use a divisor (denominator) of 100 and, voila, we have 365/100. We can see, however, that both numerator and denominator are divisible by 5 so the result can be simplified to 73/20.
But what if the number is a never-ending recurring decimal like 0.66666666... ? There's a well-known way to manage that (look at
برای دیدن تصاویر باید ثبت نام کنید
this snippet in any way intrigues you then here is the routine which did that conversion.
You are, however, warned that however intriguing it might be it is all but totally useless .....
Conversion of decimal numbers to neat integer fractions is something you may have learned at school. The basic process is easy. Given 3.65 we just push the dot two places to the right, which means multiplying by 100, then use a divisor (denominator) of 100 and, voila, we have 365/100. We can see, however, that both numerator and denominator are divisible by 5 so the result can be simplified to 73/20.
But what if the number is a never-ending recurring decimal like 0.66666666... ? There's a well-known way to manage that (look at
برای دیدن لینک ها باید ثبت نام کنید
which explains and illustrates it) but it doesn't work properly for non-terminating numbers that do not have a recurring part...
برای دیدن لینک ها باید ثبت نام کنید
برای دیدن لینک ها باید ثبت نام کنید