Feb-22-2021, 09:00 PM
It is actually pretty easy. No need to break it up into an integer and a decimal part.
Say you want 10 decimals for the square root of 1235.789 (taken from your program).
Then multiply the value with 1020 = 123578900000000000000000
Running your function on it gives 351537906917. Divide by 1010 = 35.1537906917
Correct answer!
If you want many decimals, then don't calculate the answer as an integer, just keep the figures calculated in a list [3, 5, 1, 5, 3, 7, 9, 0, 6, 9, 1, 7]. The length of the list minus the number of decimals tells you where to place the decimal point.
Say you want 10 decimals for the square root of 1235.789 (taken from your program).
Then multiply the value with 1020 = 123578900000000000000000
Running your function on it gives 351537906917. Divide by 1010 = 35.1537906917
Correct answer!
If you want many decimals, then don't calculate the answer as an integer, just keep the figures calculated in a list [3, 5, 1, 5, 3, 7, 9, 0, 6, 9, 1, 7]. The length of the list minus the number of decimals tells you where to place the decimal point.