Skip to main content
 首页 » 编程设计

python之如何在 python 中删除整数中的 .0

2025年05月04日11mq0036

我想在计算这些时间时删除 .0。

current_time = datetime.timedelta(hours = 22, minutes = 30) 
program_end = datetime.timedelta(hours = 23, minutes = 40) 
program_duration = program_end - current_time 
program_widths = int(program_duration.seconds / 60) 
program_widths = program_widths * 11.4 

输出:

794.0 

结果

>>>> 794 

你能帮我如何删除 .0 因为我使用的是整数吗?

请您参考如下方法:

使用 int 函数将您的 float 数字转换为 int:

int(794.0) # 794 

在你的程序中试试这个program_widths = int(program_widths)如果你想让你的变量变成int如果你只想把它打印成int 为打印转换为 int -> print int(program_widths)