Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple arithmetic question
#1
Hi,

I'd like to round the number 12.13 to 12 and 12.45 to 13.
None of the following functions return the format I'm looking for. I guess I could use if then function to get around it but, I'm sure there's an easy way to solve this.

TIA

import math

a = 12.13
b = 12.45

print(round(a), round(b))  # incorrect
print(math.ceil(a), math.ceil(b))  # incorrect
print(math.floor(a), math.floor(b))  # incorrect
print(math.trunc(a), math.trunc(b))  # incorrect
Reply


Messages In This Thread
Simple arithmetic question - by ebolisa - Dec-15-2021, 01:53 PM
RE: Simple arithmetic question - by deanhystad - Dec-15-2021, 02:22 PM
RE: Simple arithmetic question - by ebolisa - Dec-15-2021, 02:39 PM
RE: Simple arithmetic question - by Gribouillis - Dec-15-2021, 04:26 PM
RE: Simple arithmetic question - by bowlofred - Dec-15-2021, 04:26 PM
RE: Simple arithmetic question - by deanhystad - Dec-15-2021, 04:56 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Very Beginner question on simple variables Harvy 1 340 Apr-12-2024, 12:03 AM
Last Post: deanhystad
  Simple Question - ' defined as "a". ?' Ryan012 10 1,851 May-27-2023, 06:03 PM
Last Post: Ryan012
  Very simple question about filenames and backslashes! garynewport 4 2,135 Jan-17-2023, 05:02 AM
Last Post: deanhystad
  Python Tkinter Simple Multithreading Question AaronCatolico1 5 1,761 Dec-14-2022, 11:35 PM
Last Post: deanhystad
  A simple "If...Else" question from a beginner Serena2022 6 1,851 Jul-11-2022, 05:59 AM
Last Post: Serena2022
  Evaluating arithmetic expression with recursion. muddybucket 3 2,958 Dec-17-2021, 08:31 AM
Last Post: deanhystad
  Simple code question about lambda and tuples JasPyt 7 3,508 Oct-04-2021, 05:18 PM
Last Post: snippsat
Big Grin question about simple algorithm to my problem jamie_01 1 1,756 Oct-04-2021, 11:55 AM
Last Post: deanhystad
  Magic Method Arithmetic Operators ClownPrinceOfCrime 3 2,403 Jan-10-2021, 03:24 PM
Last Post: ndc85430
  Simple question 1234 4 2,369 Dec-04-2020, 12:29 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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