从 URL 读取 JSON 正在读取奇怪的浮点数
Reading JSON from URL is reading weird floats
我尝试读取 json 文件
输出给出奇怪的浮点数
250: 4.918e-06
251: 0.0006678
252: 4.366e-07
253: 3.0054e-06
254: 3.0942e-05
我做错了什么?
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']))
4.918e-06 是一种科学记数法,用于数学、物理、化学、天文学和其他科学领域,用于处理非常大或非常小的数字。有了科学记数法,加减乘除就简单多了。
4.918e-06 = 4.918 x 10-6 = 0.000004918
另见 Convert Scientific Notation to Float
我尝试读取 json 文件 输出给出奇怪的浮点数
250: 4.918e-06
251: 0.0006678
252: 4.366e-07
253: 3.0054e-06
254: 3.0942e-05
我做错了什么?
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']))
4.918e-06 是一种科学记数法,用于数学、物理、化学、天文学和其他科学领域,用于处理非常大或非常小的数字。有了科学记数法,加减乘除就简单多了。
4.918e-06 = 4.918 x 10-6 = 0.000004918
另见 Convert Scientific Notation to Float