当前位置: 首页>>代码示例>>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;未经允许,请勿转载。