in reply to limit of for loop!!
What are you actually trying to do? What precision (how many digits) do you really need? Moritz provided a good solution (work with integer values then scale as the last step) - what is wrong with that solution?
As an exercise try writing 1/3 as a decimal fraction in full. Let me get you started:
0.33333333333333333333333333333
Have you figured out that you can't exactly represent 1/3 as a finite decimal fraction? In the same way you can't exactly represent 1/10 (base 10) as a finite binary fraction. This seems like a problem, but for almost all real applications for arithmetic it is not an issue. You seldom need more than a few digits of precision for an answer (although for some calculations you may need more precision for intermediate answers).
So the key questions are: what are you trying to do and how much precision do you really need? There are many possible ways to solve your problem, but a solution depends very much on what you are trying to achieve.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: limit of for loop!!
by sagar123 (Novice) on Jan 02, 2012 at 07:31 UTC |