Python Forum
If a decimal is 0 how do I make it not show?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
If a decimal is 0 how do I make it not show?
#1
I'm new and only 30 minutes into Python. I'm trying to calculate something using randomly generated numbers and when I want to round it to 1 decimal I use
number2 = round(number1, 1)
But sometimes I'll get the output 1.0, 2.0, 3.0 etc
How do I make these numbers output to just 1, 2 or 3?
Reply
#2
You probably just want to call int() on the number.
Reply
#3
(Feb-08-2019, 12:25 AM)micseydel Wrote: You probably just want to call int() on the number.

I only want them to be an integer when they have the decimal "0". How do I do that?
Reply
#4
Ah, ok, yeah that's a little different. You can try using the modulo operator (e.g. your_num % 1 == 0).
Reply
#5
(Feb-08-2019, 12:57 AM)micseydel Wrote: Ah, ok, yeah that's a little different. You can try using the modulo operator (e.g. your_num % 1 == 0).

Ok, thanks.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  PIL Image im.show() no show! Pedroski55 2 927 Sep-12-2022, 10:19 PM
Last Post: Pedroski55
  Make console show after script was built with Pyinstaller --NOCONSOLE? H84Gabor 0 1,189 May-05-2022, 12:32 PM
Last Post: H84Gabor
  PIL Image im.show() no show! Pedroski55 6 4,739 Feb-08-2022, 06:32 AM
Last Post: Pedroski55
  How show decimal only for none whole number ? SpongeB0B 6 2,557 Mar-27-2020, 09:15 AM
Last Post: DeaD_EyE
  testing for Decimal w/o importing decimal every time Skaperen 7 4,363 May-06-2019, 10:23 PM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020