當前位置: 首頁>>代碼示例>>Golang>>正文


Golang strconv.Atof32函數代碼示例

本文整理匯總了Golang中strconv.Atof32函數的典型用法代碼示例。如果您正苦於以下問題:Golang Atof32函數的具體用法?Golang Atof32怎麽用?Golang Atof32使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Atof32函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: do_line

func do_line(row []string) {
	name := row[0]
	col1, _ := strconv.Atof32(row[1])
	col2, _ := strconv.Atof32(row[2])

	result := col1 * col2

	fmt.Printf("%s is %.02f\n", name, result)
}
開發者ID:TJC,項目名稱:PerfTesting,代碼行數:9,代碼來源:testread.go

示例2: float32

func (rs *ResultSet) float32(ord int) (value float32, isNull bool) {
	if rs.conn.LogLevel >= LogVerbose {
		defer rs.conn.logExit(rs.conn.logEnter("*ResultSet.float32"))
	}

	isNull = rs.isNull(ord)
	if isNull {
		return
	}

	val := rs.values[ord]

	switch rs.fields[ord].format {
	case textFormat:
		// strconv.Atof32 does not handle NaN
		if string(val) == "NaN" {
			value = float32(math.NaN())
		} else {
			var err os.Error
			value, err = strconv.Atof32(string(val))
			panicIfErr(err)
		}

	case binaryFormat:
		value = math.Float32frombits(binary.BigEndian.Uint32(val))
	}

	return
}
開發者ID:lalitjsraks,項目名稱:go-pgsql,代碼行數:29,代碼來源:resultset.go

示例3: Scan

// Scan parses the values of the current result row (set using Result.Next)
// into the given arguments.
func (r *Result) Scan(args ...interface{}) os.Error {
	if len(args) != r.ncols {
		return os.NewError(fmt.Sprintf("incorrect argument count for Result.Scan: have %d want %d", len(args), r.ncols))
	}

	for i, v := range args {
		if int(C.PQgetisnull(r.res, C.int(r.currRow), C.int(i))) == 1 {
			continue
		}
		val := C.GoString(C.PQgetvalue(r.res, C.int(r.currRow), C.int(i)))
		switch v := v.(type) {
		case *[]byte:
			if !strings.HasPrefix(val, "\\x") {
				return argErr(i, "[]byte", "invalid byte string format")
			}
			buf, err := hex.DecodeString(val[2:])
			if err != nil {
				return argErr(i, "[]byte", err.String())
			}
			*v = buf
		case *string:
			*v = val
		case *bool:
			*v = val == "t"
		case *int:
			x, err := strconv.Atoi(val)
			if err != nil {
				return argErr(i, "int", err.String())
			}
			*v = x
		case *int64:
			x, err := strconv.Atoi64(val)
			if err != nil {
				return argErr(i, "int64", err.String())
			}
			*v = x
		case *float32:
			x, err := strconv.Atof32(val)
			if err != nil {
				return argErr(i, "float32", err.String())
			}
			*v = x
		case *float64:
			x, err := strconv.Atof64(val)
			if err != nil {
				return argErr(i, "float64", err.String())
			}
			*v = x
		case *time.Time:
			x, _, err := ParseTimestamp(val)
			if err != nil {
				return argErr(i, "time.Time", err.String())
			}
			*v = *x
		default:
			return os.NewError("unsupported type in Scan: " + reflect.TypeOf(v).String())
		}
	}
	return nil
}
開發者ID:sedzinreri,項目名稱:pgsql.go,代碼行數:62,代碼來源:pgsql.go

示例4: AsFloat32

func AsFloat32(v interface{}) (float32, os.Error) {
	switch value := v.(type) {
	default:
		return 0, os.NewError(fmt.Sprintf("unexpected type: %T", value))
	case int:
		return float32(value), nil
	case int8:
		return float32(value), nil
	case int16:
		return float32(value), nil
	case int32:
		return float32(value), nil
	case int64:
		return float32(value), nil
	case uint:
		return float32(value), nil
	case uint8:
		return float32(value), nil
	case uint16:
		return float32(value), nil
	case uint32:
		return float32(value), nil
	case uint64:
		return float32(value), nil
	case float32:
		return float32(value), nil
	case float64:
		return float32(value), nil
	case string:
		return strconv.Atof32(value)
	}
	panic(fmt.Sprintf("unsupported type: %s", reflect.ValueOf(v).Type().Name()))
}
開發者ID:thomaslee,項目名稱:go-ext,代碼行數:33,代碼來源:conversions.go

示例5: F32

// Get node value as float32
func (this *Node) F32(namespace, name string) float32 {
	if node := rec_SelectNode(this, namespace, name); node != nil && node.Value != "" {
		n, _ := strconv.Atof32(node.Value)
		return n
	}
	return 0
}
開發者ID:dustywilson,項目名稱:go-pkg-xmlx,代碼行數:8,代碼來源:node.go

示例6: NewStatusMessage

func NewStatusMessage(s string) *StatusMessage {
	var msg StatusMessage
	progressRe := regexp.MustCompile("\\[download\\][ \t]+([0-9.]+)%[ \t]+of[ \t]+([0-9\\.mkgb]+) at[ \t]+([0-9.gkmb\\-]+)/s[ \t]+eta[ \t]+([0-9\\-]+):([0-9\\-]+)")
	if strings.HasPrefix(s, "[info]") && strings.Index(s, ":") != -1 {
		msg.state = kDownloadingMetadata
	} else if match := progressRe.FindStringSubmatch(strings.ToLower(s)); match != nil {
		msg.state = kDownloadingVideo
		progress, e := strconv.Atof32(match[1])
		if e != nil {
			return nil
		}
		msg.totalBytes, e = SizeStringToInt(match[2])
		if e != nil {
			return nil
		} else {
			minsRemaining, e := strconv.Atoi(match[4])
			if e == nil {
				secsRemaining, e := strconv.Atoi(match[5])
				if e != nil {
					msg.secondsRemaining = uint64(minsRemaining*60 + secsRemaining)
				}
			}

			msg.bytesTransferred =
				uint64(float32(msg.totalBytes) * (progress / 100))
		}
	} else if strings.HasPrefix(s, "[ffmpeg]") && strings.Index(s, ":") != -1 {
		msg.state = kExtractingAudio
	}

	return &msg
}
開發者ID:areusch,項目名稱:ytd-server,代碼行數:32,代碼來源:worker.go

示例7: term

/*
Get the next term from the expression.
If the next input is a number, return it.
If the next input is a parenthesis, find the value of the expression within it.

Returns:
	float32 - the value of the expression starting from the next input
*/
func term() float32 {
	var result float32
	nextInput := nextInput()
	switch nextInput {
	case "(":
		result = sum()
	case ")":
		result += 0
	default:
		if a, b := strconv.Atof32(nextInput); b == nil {
			result = a
		} else {
			if forgivenessCount == 0 {
				if nextInput != "Makefile" {
					fmt.Println(nextInput)
					os.Exit(0)
				} else {
					fmt.Println(phrase[0] + ": syntax error")
					os.Exit(2)
				}
			} else {
				fmt.Println(phrase[0] + ": non-numeric argument")
				os.Exit(2)
			}
		}
		forgivenessCount--
	}
	return result
}
開發者ID:Altece,項目名稱:Go-Go-Gadget-Repo,代碼行數:37,代碼來源:expr.go

示例8: atof

func atof(s []byte) gl.GLfloat {
	f, err := strconv.Atof32(string(s))
	if err != nil {
		panic(err)
	}
	return gl.GLfloat(f)
}
開發者ID:PragmaticCypher,項目名稱:opengl-go-tutorials,代碼行數:7,代碼來源:lesson10.go

示例9: getExchangeRate

//function that fetches the exchange rate from bitcoincharts
func getExchangeRate(c appengine.Context) float32 {

	client := urlfetch.Client(c)
	resp, err := client.Get("http://bitcoincharts.com/t/weighted_prices.json")
	if err != nil {
		log.Print("getExchangeRate err ", err)
		return -1.0
	}

	//decode the json
	dec := json.NewDecoder(resp.Body)

	var f interface{}
	if err2 := dec.Decode(&f); err != nil {
		log.Println("getExchangeRate err2 ", err2)
		return -1.0
	}

	m := f.(map[string]interface{})
	//get the value for USD 24h
	tmptocheck := m["USD"].(map[string]interface{})["24h"]

	switch v := tmptocheck.(type) {
	case string: //if value is string, it converts it
		newValue, _ := strconv.Atof32(tmptocheck.(string))
		//log.Print(newValue)
		return newValue
	default: //otherwise returns a false value (in case no data is fetched or something)
		return -1.0
	}

	return -1.0
}
開發者ID:ThePiachu,項目名稱:Bitcoin-Go-Calculator,代碼行數:34,代碼來源:calc.go

示例10: Af32

// Get attribute value as float32
func (this *Node) Af32(namespace, name string) float32 {
	if s := this.As(namespace, name); s != "" {
		n, _ := strconv.Atof32(s)
		return n
	}
	return 0
}
開發者ID:dustywilson,項目名稱:go-pkg-xmlx,代碼行數:8,代碼來源:node.go

示例11: float32

func (rs *ResultSet) float32(ord int) (value float32, isNull bool) {
	if rs.conn.LogLevel >= LogVerbose {
		defer rs.conn.logExit(rs.conn.logEnter("*ResultSet.float32"))
	}

	isNull = rs.isNull(ord)
	if isNull {
		return
	}

	val := rs.values[ord]

	switch rs.fields[ord].format {
	case textFormat:
		// strconv.Atof32 does not handle "-Infinity" and "Infinity"
		valStr := string(val)
		switch valStr {
		case "-Infinity":
			value = float32(math.Inf(-1))

		case "Infinity":
			value = float32(math.Inf(1))

		default:
			var err os.Error
			value, err = strconv.Atof32(valStr)
			panicIfErr(err)
		}

	case binaryFormat:
		value = math.Float32frombits(binary.BigEndian.Uint32(val))
	}

	return
}
開發者ID:saschpe,項目名稱:go-pgsql,代碼行數:35,代碼來源:resultset.go

示例12: GwtFloat

func GwtFloat(reg *Registry, strtable, payload []string, partype string, idxv int) (interface{}, int, os.Error) {
	v, err := strconv.Atof32(payload[idxv])
	if err != nil {
		return nil, 1, err
	}

	return v, 1, nil
}
開發者ID:hpcorona,項目名稱:gowt,代碼行數:8,代碼來源:types.go

示例13: textToValue

func (self *Slider) textToValue() {
	f, err := strconv.Atof32(self.txt)
	if err != nil {
		self.value = 0
	} else {
		self.value = float32(f)
	}
}
開發者ID:foamdino,項目名稱:libtcod-go,代碼行數:8,代碼來源:gui.go

示例14: F32

func (this *Section) F32(key string, defval float32) float32 {
	if v, ok := this.Pairs[key]; ok {
		if f, err := strconv.Atof32(v); err == nil {
			return f
		}
	}
	return defval
}
開發者ID:welterde,項目名稱:go-pkg-ini,代碼行數:8,代碼來源:section.go

示例15: splitUnits

func splitUnits(in string) (val float32, units string, err os.Error) {
	lastnum := strings.LastIndexAny(in, "0123456789.")
	units = ""
	if lastnum == -1 {
		err = os.NewError("non-numeric value")
		return
	}
	if lastnum+1 < len(in) {
		/* pd.Units = proto.String(in[lastnum+1 : len(in)])*/
		units = in[lastnum+1 : len(in)]
		val, err = strconv.Atof32(in[0 : lastnum+1])
		if err != nil {
			return 0, "", err
		}
	} else {
		val, err = strconv.Atof32(in)
	}
	return
}
開發者ID:pjjw,項目名稱:ncd,代碼行數:19,代碼來源:nagios.go


注:本文中的strconv.Atof32函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。