# How to transfer a numerical value in Mathematica into a symbolic fraction with sufficiently large precision?

Suppose I have a number $$0.26630939883535015$$ and want to transfer it into a symbolic fraction by truncating it first. The way I do it is first Round it and then Rationalize it as the following code shows

Rationalize@Round[0.26630939883535015, 0.00001]


with output $$26631/100000$$. So far so good. Since I want higher precision, so I execute the following code

Rationalize@Round[0.26630939883535015, 0.000001]


Notice that I change $$0.00001$$ into $$0.000001$$ inside Round function. The result now becomes $$0.266309$$. It does not work. Then I tried to use the following code

Rationalize[Round[0.26630939883535015, 0.000001], 0]


However, the output is $$7085634719/26606816589$$ but I expect the output to be $$266309/1000000$$.

Is there some other method that I can achieve the goal?

• want to transfer it into a symbolic fraction by truncating it first. Why truncate? You lose accuracy. The whole point of symbolic computation is that you can work with exact values as is all the time, unlink Fortran or Matlab. Commented Dec 23, 2023 at 15:13
• I would do SetAccuracy[0.26630939883535015, Infinity] which gives 4797403637440575/18014398509481984 Commented Dec 23, 2023 at 15:22
• @Nasser Thank you for your comment. For the specific problem I considered, losing some precision is harmless to me but a nicer representation of the number(such as 266309/1000000 instead of 4797403637440575/18014398509481984) is more important. But anyway, I don't know the method you mentioned and it might be very useful someday for me :) Commented Dec 23, 2023 at 23:41
• @Nasser Furthermore, you mentioned that you don't want to lose accuracy and provided a method SetAccuracy[0.26630939883535015, Infinity] which implies your method does not lose accuracy. However, I think your method also loses accuracy since the result of 26630939883535015/100000000000000000 - 4797403637440575/18014398509481984 is not zero! Commented Dec 23, 2023 at 23:47

## 2 Answers

Use exact numbers in the second argument of Round

expr = 0.26630939883535015;

Round[expr, 10^-#] & /@ Range[6]

(* {3/10, 27/100, 133/500, 2663/10000, 26631/100000, 266309/1000000} *)

• Oh, thank you very much but I didn't find it first in the documentation. It seems that if you use a decimal as the second argument of Round, it will return a decimal; if you use a fraction as the second argument of Round, then it will return a fraction. Commented Dec 24, 2023 at 0:00
• From the documentation, "If a is not a real number, Round[x, a] is given by the formula Round[x, a] == a Round[x/a]" Commented Dec 24, 2023 at 0:30

You don't need the rounding, because Rationalize has a 2nd parameter:

Table[Rationalize[0.26630939883535015, 1/10^n], {n, 10}]