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
#8
You said that you want this:
Output:
>>> foo(3.25) '3.25' >>> foo(4.0) '4' >>>
and I gave you this:
Output:
>>> def foo (floating_point_number) : ... integer = int (floating_point_number) ... if integer == floating_point_number : ... return integer ... return floating_point_number ... >>> foo (3.25) 3.25 >>> foo (4.0) 4 >>>
The only difference I see is the quotation marks. Is that what your looking for? If not, can you explain exactly what the difference is?
Reply


Messages In This Thread
RE: formatting float like int for whole values - by BashBedlam - Apr-11-2022, 01:24 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  python calculate float plus float is incorrect? sirocawa 6 2,400 Apr-16-2024, 01:45 PM
Last Post: DeaD_EyE
  Formatting float number output barryjo 2 1,896 May-04-2023, 02:04 PM
Last Post: barryjo
  ValueError - Formatting issue when values enter thousands phillyfa 4 2,395 Apr-20-2023, 06:22 PM
Last Post: phillyfa
  Write Null values as 0.0 (float) type in csv mg24 3 2,876 Dec-07-2022, 09:04 PM
Last Post: deanhystad
  Float Slider - Affecting Values in Column 'Pandas' planckepoch86 0 2,073 Jan-22-2022, 02:18 PM
Last Post: planckepoch86
  Float Formatting Kristenl2784 3 2,637 Jul-30-2020, 04:49 PM
Last Post: bowlofred
  Comaparing Float Values of Dictionary Against A Float Value & Pick Matching Key firebird 2 4,868 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 3,116 Jul-12-2018, 09:03 AM
Last Post: buran
  Can PyAudio (Port Audio) validly accept float values when writing to stream? cdrandin 1 4,615 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