Python Forum
formatting float like int for whole values
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
formatting float like int for whole values
#5
close to that. while str() isn't exactly necessary, that was what i had in mind ... that foo() did the formatting.
def foo (floating_point_number) :
    integer = int (floating_point_number)
    if integer == floating_point_number :
        return str(integer)
    return str(floating_point_number)

print (f'{foo (3.25)}, {foo (4.0)}')
Tradition is peer pressure from dead people

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


Messages In This Thread
RE: formatting float like int for whole values - by Skaperen - Apr-10-2022, 07:08 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  python calculate float plus float is incorrect? sirocawa 6 562 Apr-16-2024, 01:45 PM
Last Post: DeaD_EyE
  Formatting float number output barryjo 2 1,015 May-04-2023, 02:04 PM
Last Post: barryjo
  ValueError - Formatting issue when values enter thousands phillyfa 4 1,312 Apr-20-2023, 06:22 PM
Last Post: phillyfa
  Write Null values as 0.0 (float) type in csv mg24 3 1,504 Dec-07-2022, 09:04 PM
Last Post: deanhystad
  Float Slider - Affecting Values in Column 'Pandas' planckepoch86 0 1,473 Jan-22-2022, 02:18 PM
Last Post: planckepoch86
  Float Formatting Kristenl2784 3 1,811 Jul-30-2020, 04:49 PM
Last Post: bowlofred
  Comaparing Float Values of Dictionary Against A Float Value & Pick Matching Key firebird 2 3,491 Jul-25-2019, 11:32 PM
Last Post: scidam
  Unable to print the exact Float values when I convert LIST to Sequence of Tuples? preethamalluri 1 2,519 Jul-12-2018, 09:03 AM
Last Post: buran
  Can PyAudio (Port Audio) validly accept float values when writing to stream? cdrandin 1 3,854 Mar-26-2017, 07:54 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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