Rob
Rob

Reputation: 181

How to remove the .0 in a integter in python

I want to remove the .0 when I am calculating on these times.

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

Output:

794.0

Results

>>>> 794

Can you please help me how I can remove the .0 as I am using a integer?

Upvotes: 5

Views: 26377

Answers (3)

ᴀʀᴍᴀɴ
ᴀʀᴍᴀɴ

Reputation: 4528

Use int function to cast your float number to int:

int(794.0) # 794

and in your program try this program_widths = int(program_widths) if you want your variable become int if you want just print it as int just cast to int for print -> print int(program_widths)

Upvotes: 6

Isdj
Isdj

Reputation: 1856

You need to cast your float to an int, your option of:

int(program_widths)
print program_widths

Doesn't work because you cast it yet don't keep the result, you should just change the printing to:

print int(program_widths)

Upvotes: 0

Zizouz212
Zizouz212

Reputation: 4998

It's because it is a float. If you want an integer, you need to convert it:

int(variable)

I'm not sure what you're trying to do here though.

Upvotes: 0

Related Questions