当前位置: 首页>>代码示例>>Golang>>正文


Golang strconv.Atof64函数代码示例

本文整理汇总了Golang中strconv.Atof64函数的典型用法代码示例。如果您正苦于以下问题:Golang Atof64函数的具体用法?Golang Atof64怎么用?Golang Atof64使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Atof64函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: hasProperty

func hasProperty(a, b int) bool {
	stra := strconv.Itoa(a)
	strb := strconv.Itoa(b)
	num := uint8(0)
	den := uint8(0)
	if stra[0] == strb[0] {
		num = stra[1]
		den = strb[1]
	} else if stra[0] == strb[1] {
		num = stra[1]
		den = strb[0]
	} else if stra[1] == strb[1] && stra[1] != uint8(48) {
		num = stra[0]
		den = strb[0]
	} else if stra[1] == strb[0] {
		num = stra[0]
		den = strb[1]
	} else {
		return false
	}
	newa, _ := strconv.Atof64(string(num))
	newb, _ := strconv.Atof64(string(den))
	if float64(a)/float64(b) == newa/newb {
		return true
	}
	return false
}
开发者ID:Narsil,项目名称:go-euler,代码行数:27,代码来源:problem33.go

示例2: GetOrderBook

// GetOrderBook retrieves the limit order book.
func GetOrderBook(c appengine.Context) (x xgen.OrderBook, err os.Error) {
	defer func() {
		if e, ok := recover().(os.Error); ok {
			err = e
		}
	}()
	var b OrderBook
	err = restapi.GetJson(c, JsonDepth, &b)
	check(err)
	for _, ask := range b.Asks {
		var o xgen.Order
		o.Price, err = strconv.Atof64(ask[Price])
		check(err)
		o.Amount, err = strconv.Atof64(ask[Amount])
		check(err)
		x.SellTree = append(x.SellTree, o)
	}
	for _, bid := range b.Bids {
		var o xgen.Order
		o.Price, err = strconv.Atof64(bid[Price])
		check(err)
		o.Amount, err = strconv.Atof64(bid[Amount])
		check(err)
		x.BuyTree = append(x.BuyTree, o)
	}
	if !x.Validate() {
		panic("Invalid Depth")
	}
	sort.Sort(x.BuyTree)
	sort.Sort(x.SellTree)
	x.BuyTree.Reverse()
	return
}
开发者ID:adrianuswarmenhoven,项目名称:ArBit,代码行数:34,代码来源:tradehillapi.go

示例3: ASwissCoordToStruct

// Parses a string representation of a LV++ coordinate into a struct holding a SwissCoord coordinate value.
// The reference ellipsoid of Swisscoord datum is always the GRS80 ellipsoid.
func ASwissCoordToStruct(coord string) (*SwissCoord, os.Error) {

	compact := strings.ToUpper(strings.TrimSpace(coord))
	var rights, heights string
	var coordType, oldcoordType SwissCoordType
	var right, height float64
	var err os.Error

L1:
	for i, index := 0, 0; i < 2; i++ {
		index = strings.Index(compact, " ")
		if index == -1 {
			index = len(compact)
		}

		switch compact[:2] {
		case "X:":
			coordType = LV03
			heights = compact[2:index]
		case "Y:":
			coordType = LV03
			rights = compact[2:index]
		case "E:":
			coordType = LV95
			rights = compact[2:index]
		case "N:":
			coordType = LV95
			heights = compact[2:index]
		default:
			err = os.EINVAL
			break L1
		}

		if oldcoordType != coordType {
			err = os.EINVAL
			break L1
		}

		if i == 1 {
			break L1
		}
		compact = compact[index+len(" "):]
		compact = strings.TrimLeft(compact, " ")
		oldcoordType = coordType
	}

	if err == nil {

		right, err = strconv.Atof64(rights)
		if err == nil {

			height, err = strconv.Atof64(heights)
			if err == nil {
				return &SwissCoord{Easting: right, Northing: height, CoordType: coordType, el: cartconvert.Bessel1841Ellipsoid}, nil
			}
		}
	}

	return nil, err
}
开发者ID:CloudLife,项目名称:cartconvert,代码行数:62,代码来源:lv03p.go

示例4: convert

func (h OpenOrders) convert() (o xgen.OpenOrders) { // Convert campbx.OpenOrders to xgen.OpenOrders
	var err os.Error
	o.Sell = make(map[string]xgen.OpenOrder)
	o.Buy = make(map[string]xgen.OpenOrder)
	for _, order := range h.Buy {
		if order.Oid != "" {
			var t xgen.OpenOrder
			t.Date = time.Seconds() // Should use time.Parse to convert order.DateEntered to Unix time
			t.Price, err = strconv.Atof64(order.Price)
			check(err)
			t.Amount, err = strconv.Atof64(order.Quantity)
			check(err)
			o.Buy[order.Oid] = t
		}
	}
	for _, order := range h.Sell {
		if order.Oid != "" {
			var t xgen.OpenOrder
			t.Date = time.Seconds() // Should use time.Parse to convert order.DateEntered to Unix time
			t.Price, err = strconv.Atof64(order.Price)
			check(err)
			t.Amount, err = strconv.Atof64(order.Quantity)
			check(err)
			o.Sell[order.Oid] = t
		}
	}
	return
}
开发者ID:adrianuswarmenhoven,项目名称:ArBit,代码行数:28,代码来源:campbxapi.go

示例5: ReadCoef

func ReadCoef() Coef {
	var c Coef
	c[0], _ = strconv.Atof64(os.Args[1])
	c[1], _ = strconv.Atof64(os.Args[2])
	c[2], _ = strconv.Atof64(os.Args[3])
	return c
}
开发者ID:aquilax,项目名称:go-genetic-bet,代码行数:7,代码来源:bet.go

示例6: Less

func (p byQuality) Less(i, j int) bool {
	qi := float64(1)
	if s, ok := p[i].Param["q"]; ok {
		qi, _ = strconv.Atof64(s)
	}
	qj := float64(1)
	if s, ok := p[j].Param["q"]; ok {
		qj, _ = strconv.Atof64(s)
	}
	return qj < qi
}
开发者ID:chillicoder,项目名称:twister,代码行数:11,代码来源:headermap.go

示例7: Cmp

// Tests if value 1 is greater than value2. The values are converted to double before comparison.
// Always returns false if number format is unexpected.
func (f Gt) Cmp(v1, v2 interface{}) bool {
	d1, err := strconv.Atof64(fmt.Sprint(v1))
	if err != nil {
		return false
	}
	d2, err := strconv.Atof64(fmt.Sprint(v2))
	if err != nil {
		return false
	}
	return d1 > d2
}
开发者ID:shyrobbiani,项目名称:database,代码行数:13,代码来源:filters.go

示例8: ABMNToStruct

// Parses a string representation of a BMN-Coordinate into a struct holding a BMN coordinate value.
// The reference ellipsoid of BMN coordinates is always the Bessel ellipsoid.
func ABMNToStruct(bmncoord string) (*BMNCoord, os.Error) {

	compact := strings.ToUpper(strings.TrimSpace(bmncoord))
	var rights, heights string
	var meridian BMNMeridian
	var right, height float64
	var err os.Error

L1:
	for i, index := 0, 0; i < 3; i++ {
		index = strings.Index(compact, " ")
		if index == -1 {
			index = len(compact)
		}
		switch i {
		case 0:
			switch compact[:index] {
			case "M28":
				meridian = BMNM28
			case "M31":
				meridian = BMNM31
			case "M34":
				meridian = BMNM34
			default:
				err = os.EINVAL
				break L1
			}
		case 1:
			rights = compact[:index]
		case 2:
			heights = compact[:index]
			break L1
		}
		compact = compact[index+len(" "):]
		compact = strings.TrimLeft(compact, " ")
	}

	if err == nil {

		right, err = strconv.Atof64(rights)
		if err == nil {

			height, err = strconv.Atof64(heights)
			if err == nil {

				return &BMNCoord{Right: right, Height: height, Meridian: meridian, el: cartconvert.Bessel1841MGIEllipsoid}, nil
			}
		}
	}

	return nil, err
}
开发者ID:CloudLife,项目名称:cartconvert,代码行数:54,代码来源:bmn.go

示例9: parseTestOutput

func parseTestOutput(stderr string) (res *Stats) {
	res = new(Stats)
	for _, line := range strings.Split(stderr, "\n") {
		line = strings.TrimSpace(line)
		if asmInstrsRegexp.MatchString(line) {
			ss := asmInstrsRegexp.FindStringSubmatch(line)
			if len(ss) != 2 {
				log.Printf("parseTestOutput: could not parse AsmInstrs statistic for line=[%s]", line)
				continue
			}
			var err os.Error
			if res.AsmInstrs, err = strconv.Atoi(ss[1]); err != nil {
				log.Printf("parseTestOutput: could not parse int value of AsmInstrs statistic "+
					"for line=[%s], matched substring=[%s], err: %v", line, ss[1], err)
				continue
			}
		}
		if stackSpaceRegexp.MatchString(line) {
			ss := stackSpaceRegexp.FindStringSubmatch(line)
			if len(ss) != 2 {
				log.Printf("parseTestOutput: could not parse StackSpace statistic for line=[%s]", line)
				continue
			}
			var err os.Error
			if res.StackSpace, err = strconv.Atoi(ss[1]); err != nil {
				log.Printf("parseTestOutput: could not parse int value of StackSpace statistic "+
					"for line=[%s], matched substring=[%s], err: %v", line, ss[1], err)
				continue
			}
		}
		if execTimeRegexp.MatchString(line) {
			ss := execTimeRegexp.FindStringSubmatch(line)
			if len(ss) != 3 {
				log.Printf("parseTestOutput: could not parse ExecTime statistic for line=[%s]", line)
				continue
			}
			var err os.Error
			if res.Seconds, err = strconv.Atof64(ss[1]); err != nil {
				log.Printf("parseTestOutput: could not parse int value of Seconds statistic "+
					"for line=[%s], matched substring=[%s], err: %v", line, ss[1], err)
				continue
			}
			if res.WallSeconds, err = strconv.Atof64(ss[2]); err != nil {
				log.Printf("parseTestOutput: could not parse int value of WallSeconds statistic "+
					"for line=[%s], matched substring=[%s], err: %v", line, ss[2], err)
				continue
			}
		}
	}
	return
}
开发者ID:krasin,项目名称:llvm-side-by-side,代码行数:51,代码来源:main.go

示例10: CheckValid

func (q *QuotaQuery) CheckValid() os.Error {
	var err os.Error
	if q.low, err = strconv.Atof64(q.lowStr); err != nil {
		return err
	}
	if q.high, err = strconv.Atof64(q.highStr); err != nil {
		return err
	}

	if q.low > q.high {
		return os.NewError("value low > high\n")
	}
	return nil
}
开发者ID:gaxxx,项目名称:funx,代码行数:14,代码来源:fina.go

示例11: GetBalance

// GetBalance retrieves the account balance.
func GetBalance(c appengine.Context, login xgen.Credentials) (x xgen.Balance, err os.Error) {
	defer func() {
		if e, ok := recover().(os.Error); ok {
			err = e
		}
	}()
	var b Balance
	err = restapi.PostJson(c, JsonBalance, map[string][]string{"name": {login.Username}, "pass": {login.Password}}, &b)
	check(err)
	x[xgen.BTC], err = strconv.Atof64(b.BTC)
	check(err)
	x[xgen.USD], err = strconv.Atof64(b.USD)
	return
}
开发者ID:adrianuswarmenhoven,项目名称:ArBit,代码行数:15,代码来源:tradehillapi.go

示例12: chooseMediaType

func chooseMediaType(providedStrings []string, accept string) string {
	bestScore := -1.0
	bestMatch := ""
	accepts := splitAcceptString(accept)
	providedSets := splitAcceptArray(providedStrings)
	for _, acceptMatch := range accepts {
		for i, provided := range providedSets {
			if (acceptMatch.thetype == provided.thetype || acceptMatch.thetype == "*") && (acceptMatch.subtype == provided.subtype || acceptMatch.subtype == "*") {
				score := 100.0
				if len(provided.subtype) > 0 && len(acceptMatch.subtype) > 0 && (provided.subtype == acceptMatch.subtype || acceptMatch.subtype == "*") {
					score += 10.0
				}
				for k, v := range acceptMatch.parameters {
					if k != "q" {
						if v2, ok := provided.parameters[k]; ok && v == v2 {
							score += 1.0
						}
					}
				}
				if q, ok := acceptMatch.parameters["q"]; ok {
					if qf, err := strconv.Atof64(q); err != nil {
						score *= qf
					}
				}
				if score > bestScore {
					bestScore = score
					bestMatch = providedStrings[i]
				}
			}
		}
	}
	return bestMatch
}
开发者ID:pombredanne,项目名称:webmachine.go,代码行数:33,代码来源:util.go

示例13: Float

func (self *String) Float() (f float64) {
	var err os.Error
	if f, err = strconv.Atof64(string(*self)); err != nil {
		panic(err)
	}
	return f
}
开发者ID:machinaut,项目名称:oh,代码行数:7,代码来源:cell.go

示例14: AsFloat64

func AsFloat64(v interface{}) (float64, os.Error) {
	switch value := v.(type) {
	default:
		return 0, os.NewError(fmt.Sprintf("unexpected type: %T", value))
	case int:
		return float64(value), nil
	case int8:
		return float64(value), nil
	case int16:
		return float64(value), nil
	case int32:
		return float64(value), nil
	case int64:
		return float64(value), nil
	case uint:
		return float64(value), nil
	case uint8:
		return float64(value), nil
	case uint16:
		return float64(value), nil
	case uint32:
		return float64(value), nil
	case uint64:
		return float64(value), nil
	case float32:
		return float64(value), nil
	case float64:
		return float64(value), nil
	case string:
		return strconv.Atof64(value)
	}
	panic(fmt.Sprintf("unsupported type: %s", reflect.ValueOf(v).Type().Name()))
}
开发者ID:thomaslee,项目名称:go-ext,代码行数:33,代码来源:conversions.go

示例15: scan

func scan(v *yystype) (output int) {
	i := s.Scan()
	switch i {
	case scanner.Ident:
		switch s.TokenText() {
		case "for":
			output = tfor
		case "range":
			output = trange
		default:
			output = ident
		}
		v.s = s.TokenText()
	case scanner.String, scanner.RawString:
		output = atom
		text := s.TokenText()
		v.i = text[1 : len(text)-1]
	case scanner.Int:
		output = atom
		v.i, _ = strconv.Atoi(s.TokenText())
	case scanner.Float:
		output = atom
		v.i, _ = strconv.Atof64(s.TokenText())
	case scanner.EOF:
		output = eof
	default:
		output = i
	}
	return
}
开发者ID:bmatsuo,项目名称:gohaml,代码行数:30,代码来源:parser.go


注:本文中的strconv.Atof64函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。