Python Forum
str.format rounding to the left of the decimal
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
str.format rounding to the left of the decimal
#1
Hi, I was wondering how I could make string.format round to the left of the decimal.


>>> x = 4. 542412343
>>> '{0} rounded to {1} decimals is {2: .1f}'.format(x, 4, x) 
>>> 4.5
>>> x = 52137809
>>> '{0} rounded to {1} decimals is {2: ???}'.format(x, 4, x) 
>>> 50000000
Moreover, is there somewhere I could have accessed this information, like the help function?

Thanks
Reply


Messages In This Thread
str.format rounding to the left of the decimal - by ClassicalSoul - Mar-26-2019, 09:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  need help rounding joseph202020 7 1,441 Feb-21-2023, 08:13 PM
Last Post: joseph202020
  from numpy array to csv - rounding SchroedingersLion 6 2,393 Nov-14-2022, 09:09 PM
Last Post: deanhystad
  PyQT5 - align left frohr 7 4,204 May-07-2022, 09:56 PM
Last Post: deanhystad
  How did one column get left-justified? Mark17 6 2,052 Feb-26-2022, 11:55 PM
Last Post: deanhystad
  Random data generation sum to 1 by rounding juniorcoder 9 3,626 Oct-20-2021, 03:36 PM
Last Post: deanhystad
  Rounding issue kmll 1 1,482 Oct-08-2021, 10:35 AM
Last Post: Yoriz
  Not rounding to desired decimal places? pprod 2 2,635 Mar-05-2021, 11:11 AM
Last Post: pprod
  Decimal Rounding error project_science 4 2,854 Jan-06-2021, 03:14 PM
Last Post: project_science
  Can I format decimal places by column with a dictionary? Mark17 2 2,638 Dec-28-2020, 10:13 PM
Last Post: Mark17
  rounding and floats Than999 2 3,214 Oct-26-2020, 09:36 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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