Or I guess you don't really need to copy to_str. You can just use the
existing one with a .replace('e', 'E').Aaron Meurer On Sat, Oct 26, 2013 at 7:39 PM, Aaron Meurer <[email protected]> wrote: > It looks like SymPy uses mpmath's to_str() to print Floats, which has > the lowercase e hard-coded in. > > The best way then will be to subclass StrPrinter and override > _print_Float. You can use the exact same version as the one that's > already there, except you'll need to replace to_str with your own > version, which again can be exactly the same as the one in mpmath > except using 'E' instead of 'e' everywhere. There's no direct option > to do this from the API, but since the printing system is completely > extensible, and it's all open source, you can do what you want with > little work. > > Aaron Meurer > > On Sat, Oct 26, 2013 at 4:21 PM, Duane Nykamp <[email protected]> wrote: >> I'm writing a sympy expression to a javascript snippet in an html page that >> is then interpreted by Geogebra to set parameters in an embedded applet. >> I'm just using the string printer, as I'm not having sympy actually output >> javascript code, just the mathematical expression like "3x**2+2." >> >> Unfortunately, Geogebra does not interpret "3e-5" as "0.00005" but instead >> as the constant "3e" minus 5. It will, however, interpret "3E-5" as >> "0.00005". >> >> Is there an easy way to get sympy to output a float using scientific >> notation with a capital E? For single numbers, I can just use >> >> "%E" % expression >> >> to format it in that notation. But if expression=S("3e-17*x+1"), then this >> syntax does work, because Add cannot be converted to a float. >> >> I suppose could try to figure out how to use re.sub to replace the "e" with >> "E" after printing and before writing to the html page, but I thought there >> might be a more elegant solution. >> >> Duane >> >> -- >> 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 [email protected]. >> To post to this group, send email to [email protected]. >> Visit this group at http://groups.google.com/group/sympy. >> For more options, visit https://groups.google.com/groups/opt_out. -- 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sympy. For more options, visit https://groups.google.com/groups/opt_out.
