Python decimal 转字符串去除末尾多余的零
您可以使用字符串的'rstrip()'方法去掉字符串末尾的指定字符。在这种情况下,您可以使用'rstrip('0')'方法去掉字符串末尾的0。以下是一个示例代码:
decimal = 12.34000
string = str(decimal)
string = string.rstrip('0')
print(string)
输出结果为:12.34
原文地址: https://www.cveoy.top/t/topic/N1u 著作权归作者所有。请勿转载和采集!