Python Forum
Dealing with Exponential data
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dealing with Exponential data
#6
The values must divided by 1e15?
You can use decimal.Decimal and change the precision, but Decimal is slow.

import decimal


def convert(integers, divisor='1e15'):
    with decimal.localcontext() as ctx:
        ctx.prec = 20
        for value in integers:
            yield decimal.Decimal(value) / decimal.Decimal(divisor)


list(convert(['2229708157109627', '2204081406354342']))
Output:
[Decimal('2.229708157109627'), Decimal('2.204081406354342')]
Numpy has a float128 datatype, but 64 seems to be enough to represent the value.
Are you using a 32 bit version of Python?
With numpy I got following (Python 3.7.3 x64):

In [34]: import numpy as np                                                                                                                   

In [35]: np.float128(num)                                                                                                                     
Out[35]: 2229708157109627.0

In [36]: np.float64(num)                                                                                                                      
Out[36]: 2229708157109627.0

In [37]: np.float32(num)                                                                                                                      
Out[37]: 2229708100000000.0

In [38]: np.float128(num) / 1e15                                                                                                              
Out[38]: 2.229708157109627

In [39]: np.float64(num) / 1e15                                                                                                               
Out[39]: 2.229708157109627

In [40]: np.float32(num) / 1e15                                                                                                               
Out[40]: 2.22970811252736

In [41]: num / 1e15                                                                                                                           
Out[41]: 2.229708157109627

In [42]: num                                                                                                                                  
Out[42]: 2229708157109627
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
Dealing with Exponential data - by parthi1705 - May-29-2019, 10:07 AM
RE: Dealing with Exponential data - by buran - May-29-2019, 10:20 AM
RE: Dealing with Exponential data - by parthi1705 - May-29-2019, 10:25 AM
RE: Dealing with Exponential data - by buran - May-29-2019, 10:40 AM
RE: Dealing with Exponential data - by parthi1705 - May-30-2019, 04:27 AM
RE: Dealing with Exponential data - by buran - May-29-2019, 11:02 AM
RE: Dealing with Exponential data - by DeaD_EyE - May-29-2019, 01:45 PM
RE: Dealing with Exponential data - by buran - May-30-2019, 06:48 AM
RE: Dealing with Exponential data - by parthi1705 - May-30-2019, 09:06 AM
RE: Dealing with Exponential data - by buran - May-30-2019, 09:16 AM
RE: Dealing with Exponential data - by parthi1705 - May-30-2019, 09:58 AM
RE: Dealing with Exponential data - by buran - May-30-2019, 10:16 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Excel from SAP - dealing with formats and VBA MasterOfDestr 7 739 Feb-25-2024, 12:23 PM
Last Post: Pedroski55
  UnicodeEncodeError - Dealing with Japanese Characters fioranosnake 2 2,602 Jul-07-2022, 08:43 PM
Last Post: fioranosnake
  how to get non-exponential format Skaperen 1 1,501 Nov-21-2021, 08:51 PM
Last Post: bowlofred
  Dealing with duplicated data in a CSV file bts001 10 11,903 Sep-06-2021, 12:11 AM
Last Post: SamHobbs
  Dealing with a .json nightmare... ideas? t4keheart 10 4,509 Jan-28-2020, 10:12 PM
Last Post: t4keheart
  understanding exponential and bitwise operators srm 1 2,130 Jun-15-2019, 11:14 AM
Last Post: ThomasL
  Dealing with multiple context managers heras 5 4,847 Nov-16-2018, 09:01 AM
Last Post: DeaD_EyE
  dealing with big data of timestamp LMQ 0 2,217 Jul-27-2018, 01:23 PM
Last Post: LMQ
  dealing with spaces in file names AceScottie 5 75,848 Jun-02-2018, 01:06 PM
Last Post: AceScottie
  Dealing with strings thru mmap in Python doublezero 4 8,180 Mar-01-2017, 06:33 PM
Last Post: zivoni

Forum Jump:

User Panel Messages

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