Say you wanted a decimal answer. How do you get one? I know evalf() can be used but it counts ALL digits, not just after the decimal. For example evalf(19/4, 2) gives 4.8 but I'm looking for a function that would give 4.75
2026-03-26 04:36:50.1774499810
On
What's the easiest way to approximate an answer to n places after the decimal?
973 Views Asked by Bumbble Comm https://math.techqa.club/user/bumbble-comm/detail At
2
There are 2 best solutions below
0
On
It also depends on what is easy for you. In some ways it is best to maintain high precision in calculations and just adjust the display. There is a slight learning curve but then you know it.
Something quick and dirty on the spot, if you want 3 places after the decimal point, is floor(x)+evalf(frac(x),3). That seemed to work in a test. It would need adjustment for negative numbers.
Your example of 19/4 doesn't make the question completely clear, I think. In the case of three figures, would you want 19/400 to become 0.0475 showing 3 figures after the right-most zero, or 0.048 as exactly 3 figures to the right of the decimal point (and rounded)? I suspect that you want the latter, but give you a few alternatives anyway.
Note that there is a difference between actually adjusting the quantities and merely changing the precision with which they are displayed.
Suppose that you wanted exactly
dplaces retained for the positions representing base 10 to negative powers.Suppose now that instead you wanted exactly
dfigures retained after any leading zeroes, for the positions representing base 10 to negative powers. Notice the difference between what's above and what's below, for the 4th and 5th examples.All the above is about manipulation of the quantities. If instead all you care about is the display in Maple's User Interface, then that can be changed as an option. By line-printing with the
lprintcommand below we can see that the actual results are stored with usual precision, but they are merely displayed with only two figures shown after the decimal point.