Fix metrics node balance update issue

pull/1296/head
flicker-harmony 5 years ago
parent e41f398e3d
commit dda4a8dc63
  1. 17
      api/service/metrics/service.go

@ -2,6 +2,7 @@ package metrics
import ( import (
"fmt" "fmt"
"math"
"math/big" "math/big"
"net" "net"
"net/http" "net/http"
@ -158,19 +159,9 @@ func (s *Service) Run() {
// FormatBalance formats big.Int balance with precision. // FormatBalance formats big.Int balance with precision.
func FormatBalance(balance *big.Int) float64 { func FormatBalance(balance *big.Int) float64 {
stringBalance := balance.String() scaledBalance := new(big.Float).Quo(new(big.Float).SetInt(balance), new(big.Float).SetFloat64(math.Pow10(BalanceScale)))
if len(stringBalance) < BalanceScale { floatBalance, _ := scaledBalance.Float64()
return 0.0 return floatBalance
}
if len(stringBalance) == BalanceScale {
stringBalance = "0." + stringBalance[len(stringBalance)-BalanceScale:len(stringBalance)-BalancePrecision]
} else {
stringBalance = stringBalance[:len(stringBalance)-BalanceScale] + "." + stringBalance[len(stringBalance)-BalanceScale:len(stringBalance)-BalancePrecision]
}
if res, err := strconv.ParseFloat(stringBalance, 64); err == nil {
return res
}
return 0.0
} }
// UpdateBlockHeight updates block height. // UpdateBlockHeight updates block height.

Loading…
Cancel
Save