On 07/22/2010 04:41 PM, Martin Albrecht wrote: > On 22 July 2010 22:26, tvn <nguyenthanh...@gmail.com> 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 sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org