0

I try to read an json file Output give weird floats

250: 4.918e-06

251: 0.0006678

252: 4.366e-07

253: 3.0054e-06

254: 3.0942e-05

What I am doing wrong?

url= 'https://cryptobubbles.net/backend/data/currentBubbles1000.json'
    
    user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7'
    headers={'User-Agent':user_agent,} 
    
    req= urllib.request.Request(url,None,headers)
    teller = 0
    
    def get_data_binance():
        global teller
        json_content = json.loads(urlopen(req).read())
        for coins in json_content:
            if coins['binanceSymbol'] and coins['data']['btc']['price']:
                teller += 1
                zeroteller = str(teller)
                zero_filled_number = zeroteller.zfill(3)
                binancefilled = coins['binanceSymbol']
                #print(zero_filled_number+ ': '+binancefilled.ljust(12)+ ' '+str(coins['data']['usd']['price']))
                print (zero_filled_number+ ': '+str(coins['data']['btc']['price']))

jps
  • 20,041
  • 15
  • 75
  • 79
Morgalis
  • 49
  • 5
  • There's nothing wrong, it is just an other representation of the float, works the same. Just make sure to format it properly when printing. – Klaus D. Dec 16 '21 at 07:50
  • If you need accuracy you should be using [Decimals](https://docs.python.org/3/library/decimal.html) instead. – alextsil Dec 16 '21 at 08:27

1 Answers1

0

4.918e-06 is a scientific notation used in mathematics, physics, chemistry, astronomy and other sciences to handle either very large or very small numbers. With scientific notation adding, subtracting, multiplying and dividing numbers becomes much simpler.

4.918e-06 = 4.918 x 10-6 = 0.000004918

See also Convert Scientific Notation to Float

ip.
  • 90
  • 8