package main import ( "sig-pub/pkg/zlog" "github.com/VictoriaMetrics/metrics" "github.com/govalues/decimal" ) func main() { open := metrics.NewCounter("open") open.Set(1234) // curl -H 'Content-Type: application/json' --data-binary "@vmdata.json" -X POST http://localhost:8428/api/v1/import testDecimalScale() } type BTC struct { Price decimal.Decimal } func testDecimalScale() { price := decimal.MustParse("44268500") scale, _ := decimal.Ten.PowInt(4) // price, _ = price.Mul(scale) // zlog.Info(scale) // zlog.Info(price) price, _ = price.Quo(scale) zlog.Info(price) } func testDecimal() { // zlog.Init() // var interval = "1m" // interval0 := types.Interval(interval) // sec, _ := interval0.Seconds() // zlog.Infof("hello...: %s, %s, %d", pb.Exchange_OKX.String(), pb.Exchange_BINANCE.String()) // data := `{"price":"1.23456"}` // btc := new(BTC) // err := json.Unmarshal([]byte(data), btc) // if err != nil { // panic(err) // } // fmt.Println(btc) // bytes, err := json.Marshal(btc) // if err != nil { // panic(err) // } // fmt.Println(string(bytes)) // AIDOGE price sz := decimal.MustParse("6672864381598761234.752194906") f, ok := sz.Float64() if !ok { zlog.Error("error parse value") } zlog.Info(sz, f, int64(f)) scale, _ := decimal.Ten.PowInt(sz.Scale()) // price := decimal.MustParse("0.0000000001713") // // zlog.Info(sz.Scale()) // // quantity := decimal.MustNew(int64(sz.Scale()), 0) // price, _ = price.Mul(scale) // price_i64, _, _ := price.Int64(0) // zlog.Info(price_i64) _ = scale price0 := int64(1713) // price_i64, _ := decimal.NewFromInt64(0, price0, sz.Scale()) // zlog.Info(price_i64) price_i64, _ := decimal.NewFromInt64(price0, 0, 0) price, _ := price_i64.Quo(scale) zlog.Info(price) }