stupid of me -- totally didn't pay attention to python string function ... thanks all
On Jul 22, 4:06 pm, Mitesh Patel <[email protected]> wrote: > On 07/22/2010 04:41 PM, Martin Albrecht wrote: > > > On 22 July 2010 22:26, tvn <[email protected]> wrote: > >> is there a trick to convert RealLiteral numbers to strings without > >> the trailing zeros? e.g., 2.000000000000 and 0.55550500000 become 2 > >> and 0.555505 respectively -- > > > sage: str(0.53253453425).rstrip(".0") > > '0.53253453425' > > sage: str(2).rstrip(".0") > > '2' > > You might need to be careful about "rstripping" more than one character [1]: > > sage: str(2010.000).rstrip('.0') > '201' > > But > > sage: str(2010.000).rstrip('0').rstrip('.') > '2010' > > seems to work. > > [1]http://docs.python.org/library/stdtypes.html#str.rstrip > > str.lstrip and str.strip work similarly. -- To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
