I'm trying to find the right power of 10 to multiply by, so that there are no numbers past the decimal. For example, for 3.28, it would be 100, to change it to 328. What would be the simplest way to do this?
What's wrong with a loop? You could easily do a repeat loop, but whatever…
The main thing you need to know is the number of digits in the fPart() of N, which can be found here. So, the code would be
fPart(N N10^(not(Ans)+sum(0 or fPart(abs(Ans10^(cumSum(binomcdf(13,0))-2-int(log(abs(Ans+not(Ans where N is your number. Also, you can use the 10^( token rather than typing it out.
Would a repeat loop be faster?
It would probably be much slower.
To find the number of digits in the fractional part of a number whose magnitude is greater than 0.1, use this routine by Weregoose:
sum(0 or fPart(Ans10^(cumSum(not(binompdf(14,0
If you actually want to multiply by the smallest power of ten required to return an integer, by can just multiply ten to that power by your number. For nonnegative Ans:
Ans10^(cumSum(not(binompdf(14,0 //returns a list min(Ans+E20not(not(fPart(Ans
This is probably suboptimal but I can't think of a better routine.
The reason I need this is so I can make a one line fraction to decimal converter. I just have to multiply the number by 10^(number of digits past decimal), and then find the gcd of that and 10^(number of digits past decimal), and divide both by the gcd.
so for example.
so 7.25 = 29/4
Would there be a simpler way of doing this?
This will not work as a decimal to fraction converter for any fraction whose denominator contains prime factors other than 2 or 5; in other words any repeating decimal.
For example, 1/6 is .16666666666666 (maybe it ends with a 7? Doesn't matter.) in the calculator's memory, but trying to find the gcd of 16666666666666 and 100000000000000 will give you an error because the numbers are too big, and even if it didn't it would give you a wrong answer.
Hmmmm. I didn't think about this… but technically, .16666666666666 is not 1/6, it's
So the problem is, the calculator has no way of knowing whether you meant 1/6 or that^
I know the decimal to fraction converter that uses the Euclidean algorithm avoids this by testing for E-9, instead of 0, but IDK if that would be possible here.
The only other way i could think of is to use the method of converting a repeating decimal to fraction using infinite geometric series, but that'll be a bit rough trying to find the right repeating pattern.
But thats for repeating decimals, not for finite decimals
The Silver Phantom welcomes you