Bottom Page

• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 If a decimal is 0 how do I make it not show? GamingDay Unladen Swallow Posts: 3 Threads: 1 Joined: Feb 2019 Reputation: 0 Likes received: 0 #1 Feb-08-2019, 12:22 AM 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? micseydel Involuntary Spiderweb Collector Posts: 2,158 Threads: 55 Joined: Sep 2016 Reputation: 59 Likes received: 644 #2 Feb-08-2019, 12:25 AM You probably just want to call int() on the number. Feel like you're not getting the answers you want? Checkout the help/rules for things like what to include/not include in a post, how to use code tags, how to ask smart questions, and more. Pro-tip - there's an inverse correlation between the number of lines of code posted and my enthusiasm for helping with a question :) GamingDay Unladen Swallow Posts: 3 Threads: 1 Joined: Feb 2019 Reputation: 0 Likes received: 0 #3 Feb-08-2019, 12:44 AM (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? micseydel Involuntary Spiderweb Collector Posts: 2,158 Threads: 55 Joined: Sep 2016 Reputation: 59 Likes received: 644 #4 Feb-08-2019, 12:57 AM Ah, ok, yeah that's a little different. You can try using the modulo operator (e.g. `your_num % 1 == 0`). Feel like you're not getting the answers you want? Checkout the help/rules for things like what to include/not include in a post, how to use code tags, how to ask smart questions, and more. Pro-tip - there's an inverse correlation between the number of lines of code posted and my enthusiasm for helping with a question :) GamingDay Unladen Swallow Posts: 3 Threads: 1 Joined: Feb 2019 Reputation: 0 Likes received: 0 #5 Feb-08-2019, 01:00 AM (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. « Next Oldest | Next Newest »

Top Page

 Possibly Related Threads... Thread Author Replies Views Last Post testing for Decimal w/o importing decimal every time Skaperen 7 759 May-06-2019, 10:23 PM Last Post: Skaperen

Forum Jump:

Users browsing this thread: 1 Guest(s)