I believe it uses round-to-even, but note that the rounding is done in base-2, not base-10. If you're worried about the rounding, you can evaluate the number to more digits using evalf() to see exactly how it rounded.
If you want to use a specific base-10 rounding mode, I believe currently the only way is to get a float with sufficient digits from evalf() then use the methods in the standard library decimal module. Aaron Meurer On Thu, Dec 2, 2021 at 11:23 AM Damien Desfontaines <damien.desfontai...@tmlt.io> wrote: > > Hi all, > > This feels like a very simple problem, but I couldn't find a clear answer in > the documentation. I have a sympy number x and I would like to round it to > the nearest float. Suppose I simply use float(x), and that the true value of > x is between two successive floats a and b. > - If x is slightly closer to a than b, is sympy guaranteed to round to a? > Same question if x is slightly closer to b. > - If x is exactly equal to (a+b)/2, will float(x) round it up or down? > - Are there situations where sympy can't be sure whether to round up or down? > What happens then? Is there a way to detect when that happens? > > Thanks a ton in advance, > > Damien > > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sympy+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sympy/aa33ca28-6a88-44f8-b872-9fa6717eb22cn%40googlegroups.com. -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sympy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAKgW%3D6%2BmkZTkT8euALht0TiyvUBHWTU%2B6xjCde8YrrCWzmNtaw%40mail.gmail.com.