我無法在 Go 中使用 BigInt.Div() 時(shí)獲取值。大整數(shù): totalAllocPoint, _ := instance_polypup.TotalAllocPoint(&bind.CallOpts{}) //*big.int fmt.Println("totalAllocPoint: ", totalAllocPoint)// 54000 poolInfoStruct, _ := instance_polypup.PoolInfo(&bind.CallOpts{}, &pid) //*big.int fmt.Println("allocPoint: ", poolInfoStruct.AllocPoint)// 2000我試圖使用以下代碼進(jìn)行劃分,始終返回0: poolInfoStruct.AllocPoint.Div(poolInfoStruct.AllocPoint, totalAllocPoint) fmt.Println("poolAlloc: ", poolInfoStruct.AllocPoint) poolAlloc := big.NewInt(0).Div(poolInfoStruct.AllocPoint, totalAllocPoint) fmt.Println("poolAlloc: ", poolAlloc) poolAlloc := big.NewInt(0) poolAlloc.Div(poolInfoStruct.AllocPoint, totalAllocPoint) fmt.Println("poolAlloc: ", poolAlloc)
1 回答

守候你守候我
TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超10個(gè)贊
Int.Div()
是一個(gè)整數(shù)除法運(yùn)算。你除以哪個(gè)是.這將永遠(yuǎn)是,因?yàn)槌龜?shù)大于股息。poolInfoStruct.AllocPoint
totalAllocPoint
2000 / 54000
0
也許你想要相反的?totalAllocPoint / poolInfoStruct.AllocPoint
請(qǐng)參閱此示例:
totalAllocPoint := big.NewInt(54000) allocPoint := big.NewInt(2000) totalAllocPoint.Div(totalAllocPoint, allocPoint) fmt.Println(totalAllocPoint)
哪個(gè)輸出(在Go游樂場上嘗試)。27
您指出除數(shù)和股息是正確的。如果是這樣,則不能用于此目的,因?yàn)橹荒鼙硎菊麛?shù)。big.Int
big.Int
你可以使用大。例如,浮點(diǎn)
數(shù),并使用浮點(diǎn)數(shù).Quo()
來計(jì)算商。
例如:
totalAllocPoint := big.NewInt(54000) allocPoint := big.NewInt(2000) tot := big.NewFloat(0).SetInt(totalAllocPoint) ap := big.NewFloat(0).SetInt(allocPoint) tot.Quo(ap, tot) fmt.Println(tot)
輸出(在Go游樂場上嘗試):
0.037037037037037035
tot := big.NewRat(0, 1).SetInt(totalAllocPoint) ap := big.NewRat(0, 1).SetInt(allocPoint) tot.Quo(ap, tot) fmt.Println(tot)
輸出(在Go游樂場上嘗試):
1/27
- 1 回答
- 0 關(guān)注
- 82 瀏覽
添加回答
舉報(bào)
0/150
提交
取消