Python Forum
Controlling trailing zeros with rounding?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Controlling trailing zeros with rounding?
#2
round is doing the rouding mathematically, so if last decimal(s) is zero(es) it will omit them from printing. Try with the format method instead:
print('${:.2f}'.format(round(floatsList[1], 2)))
Reply


Messages In This Thread
RE: Controlling trailing zeros with rounding? - by j.crater - Jan-25-2018, 07:23 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Controlling program with TCP commands lavacode 1 555 Jul-10-2023, 04:39 PM
Last Post: deanhystad
  need help rounding joseph202020 7 1,341 Feb-21-2023, 08:13 PM
Last Post: joseph202020
  from numpy array to csv - rounding SchroedingersLion 6 2,208 Nov-14-2022, 09:09 PM
Last Post: deanhystad
  Removing leading\trailing spaces azizrasul 8 2,726 Oct-23-2022, 11:06 PM
Last Post: azizrasul
  Controlling text-to-speech pauses with pyttsx3 pmac1300 4 4,484 Mar-14-2022, 06:47 AM
Last Post: Coricoco_fr
  remove zeros at the end of a number Frankduc 7 2,182 Feb-25-2022, 03:48 PM
Last Post: Frankduc
  Controlling what get outputted to stdout when running external commands Daring_T 4 2,183 Jan-30-2022, 05:40 PM
Last Post: bowlofred
  Random data generation sum to 1 by rounding juniorcoder 9 3,459 Oct-20-2021, 03:36 PM
Last Post: deanhystad
  Rounding issue kmll 1 1,426 Oct-08-2021, 10:35 AM
Last Post: Yoriz
  Solving for zeros of an equation! fmitchell17 0 1,843 Apr-05-2021, 07:49 PM
Last Post: fmitchell17

Forum Jump:

User Panel Messages

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