Python Forum
Inclusive (closed) range with float numbers
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Inclusive (closed) range with float numbers
#4
Obviously, it's very practical what you mentioned. For now, it's the simplest solution.

Thanks Yoriz

(Apr-27-2019, 08:47 PM)Gribouillis Wrote: Notice this in the documentation of numpy.arange()
[quote=numpy documentation] When using a non-integer step, such as 0.1, the results will often not
be consistent. It is better to use linspace for these cases.

Yes, I am getting an extremely long float at 0.47

I am formatting all this as follows ...
import numpy as np
from numpy import linspace

myRange = list(np.linspace(0.45, 0.6, 16))
myFormattedRange = ['%.2f'% elem for elem in myRange]
Output:
print(myRange) [0.45, 0.46, 0.47000000000000003, 0.48, 0.49, 0.5, 0.51, 0.52, 0.53, 0.54, 0.55, 0.56, 0.57, 0.58, 0.59, 0.6] print(myFormattedRange) ['0.45', '0.46', '0.47', '0.48', '0.49', '0.50', '0.51', '0.52', '0.53', '0.54', '0.55', '0.56', '0.57', '0.58', '0.59', '0.60']
Reply


Messages In This Thread
RE: Inclusive (closed) range with float numbers - by mapg - Apr-27-2019, 08:49 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  python calculate float plus float is incorrect? sirocawa 6 390 Apr-16-2024, 01:45 PM
Last Post: DeaD_EyE
  This result object does not return rows. It has been closed automatically dawid294 6 1,238 Mar-30-2024, 03:08 AM
Last Post: NolaCuriel
  matplotlib x axis range goes over the set range Pedroski55 5 3,282 Nov-21-2021, 08:40 AM
Last Post: paul18fr
  A question about 'Event loop is closed' fc5igm 2 2,273 Oct-05-2021, 02:00 AM
Last Post: fc5igm
  ValueError: I/O operation on closed file problem aliwien 0 2,146 Apr-23-2021, 05:50 PM
Last Post: aliwien
  Run an app in a standalone terminal and wait until it's closed glestwid 2 2,555 Aug-30-2020, 08:14 AM
Last Post: glestwid
  Return prime numbers from range krzyfigh 2 1,960 Apr-20-2020, 08:08 PM
Last Post: krzyfigh
  Define a range, return all numbers of range that are NOT in csv data KiNeMs 18 7,161 Jan-24-2020, 06:19 AM
Last Post: KiNeMs
  Comaparing Float Values of Dictionary Against A Float Value & Pick Matching Key firebird 2 3,431 Jul-25-2019, 11:32 PM
Last Post: scidam
  Print Numbers starting at 1 vertically with separator for output numbers Pleiades 3 3,778 May-09-2019, 12:19 PM
Last Post: Pleiades

Forum Jump:

User Panel Messages

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