Home > Blockchain >  Reading JSON from URL is reading weird floats
Reading JSON from URL is reading weird floats

Time:12-16

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']))

CodePudding user response:

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

  • Related