Python Forum
functio to do fixed formatting of int/float
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
functio to do fixed formatting of int/float
#1
i have wanted this function a few times now. so i have started developing one. the needs are more acute than what format() provides.

it needs a hard fixed size the caller can specify. if the number cannot fit in the space, do not enlarge the space or cut off the number. just convert it to as many * characters as needed to fill the space.

the decimal point, shown blank if the given value is int, should line up if it can, or move only to the right (fewer fraction digits) to make a larger number fit.

no trailing 0 digits in the fractional part. " 3.75 " instead of " 3.7500".

caller provides whole field size and preferred number of fraction digits, basically specifying the vertical line up of the decimal point for numbers that fit.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  defining function in a functio and sharing variables Skaperen 0 919 Feb-16-2023, 02:28 AM
Last Post: Skaperen
  precision in formatting float Skaperen 2 1,403 May-01-2022, 10:23 PM
Last Post: Skaperen
  quest for better float formatting Skaperen 0 1,015 Mar-02-2022, 08:34 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