Objects can define their behavior with format() by defining
__format__. See
https://docs.python.org/3/reference/datamodel.html#object.__format__.
We should implement it, since we can potentially format at a higher
precision than float(). Does mpmath implement it?

Aaron Meurer

On Thu, Jun 12, 2014 at 8:06 PM, Amit Saha <amitsaha...@gmail.com> wrote:
> On Thu, Jun 12, 2014 at 7:26 AM, Sergey Kirpichev <skirpic...@gmail.com> 
> wrote:
>>
>>
>> On Monday, June 9, 2014 5:35:34 AM UTC+4, Amit Saha wrote:
>>>
>>> I came across this:
>>>
>>> >>> from sympy import Float
>>> >>> Float(1.25343)
>>> 1.25343000000000
>>>
>>> >>> '{0:.2f}'.format(Float(1.25343))
>>> Traceback (most recent call last):
>>>   File "<stdin>", line 1, in <module>
>>> ValueError: Unknown format code 'f' for object of type 'str'
>>>
>>> Is this known/expected? Shouldn't it work?
>>
>>
>> Why?  "f" stands for builtin float, not Float.
>
> Yes, never mind. I forgot about how Python's numbers and SymPy's
> numbers interact.
>
>
>
>
> --
> http://echorand.me
>
> --
> 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 post to this group, send email to sympy@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sympy/CANODV3kBjuMff1tfqVQsj-K%3D6NQi6mbfzgy4-LxzCndo_fUWMQ%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAKgW%3D6KFDQrKqk-H2Xwkdj_jmSsSNMEWcWX%3D4h04q_oqEf8AmA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to