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


Golang strconv.Ftoa32函数代码示例

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


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

示例1: atos

// any to string
func atos(i interface{}) (s string) {
	switch t := i.(type) {
	case int64:
		s = strconv.Itoa64(t)
	case uint64:
		s = strconv.Uitoa64(t)
	case float32:
		s = strconv.Ftoa32(t, 'f', -1)
	case float64:
		s = strconv.Ftoa64(t, 'f', -1)
	case []byte:
		s = string(t)
	case Date:
		return t.String()
	case Time:
		return t.String()
	case DateTime:
		return t.String()
	case string:
		return t
	default:
		panic("Not a string or compatible type")
	}
	return
}
开发者ID:sudheesh001,项目名称:nodejs,代码行数:26,代码来源:convert.go

示例2: AsString

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

示例3: valueToString

func valueToString(v reflect.Value) (string, os.Error) {
	if v == nil {
		return "null", nil
	}

	switch v := v.(type) {
	case *reflect.PtrValue:
		return valueToString(reflect.Indirect(v))
	case *reflect.InterfaceValue:
		return valueToString(v.Elem())
	case *reflect.BoolValue:
		x := v.Get()
		if x {
			return "true", nil
		} else {
			return "false", nil
		}

	case *reflect.IntValue:
		return strconv.Itoa(v.Get()), nil
	case *reflect.Int8Value:
		return strconv.Itoa(int(v.Get())), nil
	case *reflect.Int16Value:
		return strconv.Itoa(int(v.Get())), nil
	case *reflect.Int32Value:
		return strconv.Itoa(int(v.Get())), nil
	case *reflect.Int64Value:
		return strconv.Itoa64(v.Get()), nil

	case *reflect.UintValue:
		return strconv.Uitoa(v.Get()), nil
	case *reflect.Uint8Value:
		return strconv.Uitoa(uint(v.Get())), nil
	case *reflect.Uint16Value:
		return strconv.Uitoa(uint(v.Get())), nil
	case *reflect.Uint32Value:
		return strconv.Uitoa(uint(v.Get())), nil
	case *reflect.Uint64Value:
		return strconv.Uitoa64(v.Get()), nil
	case *reflect.UintptrValue:
		return strconv.Uitoa64(uint64(v.Get())), nil

	case *reflect.FloatValue:
		return strconv.Ftoa(v.Get(), 'g', -1), nil
	case *reflect.Float32Value:
		return strconv.Ftoa32(v.Get(), 'g', -1), nil
	case *reflect.Float64Value:
		return strconv.Ftoa64(v.Get(), 'g', -1), nil

	case *reflect.StringValue:
		return v.Get(), nil
	case *reflect.SliceValue:
		typ := v.Type().(*reflect.SliceType)
		if _, ok := typ.Elem().(*reflect.Uint8Type); ok {
			return string(v.Interface().([]byte)), nil
		}
	}
	return "", os.NewError("Unsupported type")
}
开发者ID:mikelikespie,项目名称:redis.go,代码行数:59,代码来源:redis.go

示例4: floatv

func (e *encoder) floatv(tag string, in reflect.Value) {
	// FIXME: Handle 64 bits here.
	s := strconv.Ftoa32(float32(in.Float()), 'g', -1)
	switch s {
	case "+Inf":
		s = ".inf"
	case "-Inf":
		s = "-.inf"
	case "NaN":
		s = ".nan"
	}
	e.emitScalar(s, "", tag, C.YAML_PLAIN_SCALAR_STYLE)
}
开发者ID:ashokgelal,项目名称:goyaml,代码行数:13,代码来源:encode.go

示例5: formatReflectValue

func formatReflectValue(x reflect.Value) (string, os.Error) {
	/*
	   if !x.CanSet() {
	       return "", ErrorCantSet
	   }
	*/
	var (
		errc os.Error
		kind = x.Kind()
		//vintstr   string
	)
	switch kind {
	// Format pointers to standard types.
	case reflect.String:
		return x.Interface().(string), nil
	case reflect.Int:
		return strconv.Itoa(x.Interface().(int)), nil
	case reflect.Int8:
		return strconv.Itoa64(int64(x.Interface().(int8))), nil
	case reflect.Int16:
		return strconv.Itoa64(int64(x.Interface().(int16))), nil
	case reflect.Int32:
		return strconv.Itoa64(int64(x.Interface().(int32))), nil
	case reflect.Int64:
		return strconv.Itoa64(x.Interface().(int64)), nil
	case reflect.Uint:
		return strconv.Uitoa(x.Interface().(uint)), nil
	case reflect.Uint8:
		return strconv.Uitoa64(uint64(x.Interface().(uint8))), nil
	case reflect.Uint16:
		return strconv.Uitoa64(uint64(x.Interface().(uint16))), nil
	case reflect.Uint32:
		return strconv.Uitoa64(uint64(x.Interface().(uint32))), nil
	case reflect.Uint64:
		return strconv.Uitoa64(x.Interface().(uint64)), nil
	case reflect.Float32:
		return strconv.Ftoa32(x.Interface().(float32), FloatFmt, FloatPrec), nil
	case reflect.Float64:
		return strconv.Ftoa64(x.Interface().(float64), FloatFmt, FloatPrec), nil
	case reflect.Complex64:
		fallthrough
	case reflect.Complex128:
		errc = ErrorUnimplemented
	case reflect.Bool:
		return strconv.Btoa(x.Interface().(bool)), nil
	default:
		errc = ErrorFieldType
	}
	return "", errc
}
开发者ID:newblue,项目名称:csvutil,代码行数:50,代码来源:row.go

示例6: encodeParamValues

// Encode values fro each field
func encodeParamValues(a []interface{}) ([]byte, int) {
	var b []byte
	for i := 0; i < len(a); i++ {
		f := a[i]
		switch t := f.(type) {
		case string:
			b = append(b, packString(string(t))...)
		case int:
			b = append(b, packString(strconv.Itoa(int(t)))...)
		case float32:
			b = append(b, packString(strconv.Ftoa32(float32(t), 'f', -1))...)
		case float64:
			b = append(b, packString(strconv.Ftoa64(float64(t), 'f', -1))...)
		}
	}
	return b, len(b)
}
开发者ID:newblue,项目名称:Go-MySQL-Client-Library,代码行数:18,代码来源:mysql_stmt.go

示例7: Project

func (m *SelectManager) Project(any interface{}) *SelectManager {
	switch val := any.(type) {
	case ast.Node:
		m.project(val)
	case string:
		m.project(ast.NewSqlLiteral(any.(string)))
	case bool:
		m.project(ast.NewSqlLiteral(strconv.Btoa(any.(bool))))
	case int:
		m.project(ast.NewSqlLiteral(strconv.Itoa(any.(int))))
	case int64:
		m.project(ast.NewSqlLiteral(strconv.Itoa64(any.(int64))))
	case float32:
		m.project(ast.NewSqlLiteral(strconv.Ftoa32(any.(float32), 'f', 0)))
	case float64:
		m.project(ast.NewSqlLiteral(strconv.Ftoa64(any.(float64), 'f', 0)))
	}
	return m
}
开发者ID:jonochang,项目名称:Gorel,代码行数:19,代码来源:select_manager.go

示例8: Convert

func (c *ToSql) Convert(unknown interface{}) (s string) {
	switch val := unknown.(type) {
	case string:
		s = strconv.Quote(val)
	case bool:
		s = strconv.Btoa(val)
	case int:
		s = strconv.Itoa(val)
	case int64:
		s = strconv.Itoa64(val)
	case uint:
		s = strconv.Uitoa(val)
	case uint64:
		s = strconv.Uitoa64(val)
	case float32:
		s = strconv.Ftoa32(val, 'f', -1)
	case float64:
		s = strconv.Ftoa64(val, 'f', -1)
	default:
		s = c.ConvertUnknown(unknown)
	}
	return
}
开发者ID:jonochang,项目名称:Gorel,代码行数:23,代码来源:to_sql.go

示例9: writeBind

func (conn *Conn) writeBind(stmt *Statement) {
	values := make([]string, len(stmt.params))

	var paramValuesLen int
	for i, param := range stmt.params {
		value := param.value
		if val, ok := value.(uint64); ok {
			value = int64(val)
		}

		switch val := value.(type) {
		case bool:
			if val {
				values[i] = "t"
			} else {
				values[i] = "f"
			}

		case byte:
			values[i] = string([]byte{val})

		case float32:
			values[i] = strconv.Ftoa32(val, 'f', -1)

		case float64:
			values[i] = strconv.Ftoa64(val, 'f', -1)

		case int:
			values[i] = strconv.Itoa(val)

		case int16:
			values[i] = strconv.Itoa(int(val))

		case int32:
			values[i] = strconv.Itoa(int(val))

		case int64:
			switch param.typ {
			case Date:
				values[i] = time.SecondsToUTC(val).Format("2006-01-02")

			case Time, TimeTZ:
				values[i] = time.SecondsToUTC(val).Format("15:04:05")

			case Timestamp, TimestampTZ:
				values[i] = time.SecondsToUTC(val).Format("2006-01-02 15:04:05")

			default:
				values[i] = strconv.Itoa64(val)
			}

		case nil:

		case *big.Rat:
			if val.IsInt() {
				values[i] = val.Num().String()
			} else {
				// FIXME: Find a better way to do this.
				prec999 := val.FloatString(999)
				trimmed := strings.TrimRight(prec999, "0")
				sepIndex := strings.Index(trimmed, ".")
				prec := len(trimmed) - sepIndex - 1
				values[i] = val.FloatString(prec)
			}

		case string:
			values[i] = val

		case *time.Time:
			switch param.typ {
			case Date:
				values[i] = val.Format("2006-01-02")

			case Time, TimeTZ:
				values[i] = val.Format("15:04:05")

			case Timestamp, TimestampTZ:
				values[i] = val.Format("2006-01-02 15:04:05")

			default:
				panic("invalid use of *time.Time")
			}

		default:
			panic("unsupported parameter type")
		}

		paramValuesLen += len(values[i])
	}

	msgLen := int32(4 +
		len(stmt.portalName) + 1 +
		len(stmt.name) + 1 +
		2 + 2 +
		2 + len(stmt.params)*4 + paramValuesLen +
		2 + 2)

	conn.writeFrontendMessageCode(_Bind)
	conn.writeInt32(msgLen)
	conn.writeString0(stmt.portalName)
//.........这里部分代码省略.........
开发者ID:saschpe,项目名称:go-pgsql,代码行数:101,代码来源:conn_write.go

示例10: Fmt_G32

// Fmt_G32 formats a float32 in the 'f' or 'E' form according to size.
func (f *Fmt) Fmt_G32(v float32) *Fmt {
	return fmtString(f, strconv.Ftoa32(v, 'G', doPrec(f, -1)))
}
开发者ID:edisonwsk,项目名称:golang-on-cygwin,代码行数:4,代码来源:format.go

示例11: Fmt_fb32

// Fmt_fb32 formats a float32 in the form -123p3 (exponent is power of 2).
func (f *Fmt) Fmt_fb32(v float32) *Fmt { return fmtString(f, strconv.Ftoa32(v, 'b', 0)) }
开发者ID:edisonwsk,项目名称:golang-on-cygwin,代码行数:2,代码来源:format.go

示例12: CoerceData


//.........这里部分代码省略.........
			if b {
				return "true", true
			}
			return "false", true
		}
		if b, ok := data.(int8); ok {
			return string(b), true
		}
		if b, ok := data.(int16); ok {
			return string(b), true
		}
		if b, ok := data.(int32); ok {
			return string(b), true
		}
		if b, ok := data.(int64); ok {
			return string(b), true
		}
		if b, ok := data.(uint); ok {
			return string(b), true
		}
		if b, ok := data.(uint8); ok {
			return string(b), true
		}
		if b, ok := data.(uint16); ok {
			return string(b), true
		}
		if b, ok := data.(uint32); ok {
			return string(b), true
		}
		if b, ok := data.(uint64); ok {
			return string(b), true
		}
		if b, ok := data.(float32); ok {
			return strconv.Ftoa32(b, 'g', -1), true
		}
		if b, ok := data.(float64); ok {
			return strconv.Ftoa64(b, 'g', -1), true
		}
		return "", false
	case BINARY:
		if b, ok := data.([]byte); ok {
			return b, true
		}
		if b, ok := data.(Enumer); ok {
			if i1, ok := data.(int); ok {
				return []byte(string(i1)), true
			}
			return []byte(b.String()), true
		}
		if b, ok := data.(Stringer); ok {
			return []byte(b.String()), true
		}
		if b, ok := data.(string); ok {
			return []byte(b), true
		}
		if b, ok := data.(int); ok {
			return []byte(string(b)), true
		}
		if b, ok := data.(byte); ok {
			return []byte(string(b)), true
		}
		if b, ok := data.(bool); ok {
			if b {
				return []byte("true"), true
			}
			return []byte("false"), true
开发者ID:pombredanne,项目名称:thrift4go,代码行数:67,代码来源:ttype.go

示例13: Fmt_f32

// Fmt_f32 formats a float32 in the form -1.23.
func (f *Fmt) Fmt_f32(v float32) *Fmt {
	return fmtString(f, strconv.Ftoa32(v, 'f', doPrec(f, 6)))
}
开发者ID:edisonwsk,项目名称:golang-on-cygwin,代码行数:4,代码来源:format.go

示例14: output

// output gives out the PDF representation of v.
func output(v interface{}) []byte {
	// Check for nil
	if v == nil {
		return []byte("null")
	}

	// Check simple types with simple type assertion
	switch t := v.(type) {
	case outputter:
		return t.output()
	case bool:
		if t {
			return []byte("true")
		} else {
			return []byte("false")
		}
	case int:
		return []byte(strconv.Itoa(t))
	case float32:
		return []byte(strconv.Ftoa32(t, 'f', -1))
	case float64:
		// TODO 2.3 prints 2.299999952316284. Is it OK with PDF?
		return []byte(strconv.Ftoa64(t, 'f', -1))
	case string:
		// TODO non-ASCII characters?
		// TODO escapes, \n, \t, etc. (p. 54)
		// TODO break long lines (p. 54)
		// TODO what about hexadecimal strings? (p. 56)
		return []byte("(" + t + ")")
	case name:
		// TODO escape non-regular characters using # (p. 57)
		// TODO check length limit (p. 57)
		return []byte("/" + string(t))
	case []byte:
		return outputStream(t)
	case *bytes.Buffer:
		return outputStream(t.Bytes())
	case reflect.Value:
		return output(t.Interface())
	}

	switch r := reflect.ValueOf(v); r.Kind() {
	case reflect.Invalid:
		panic("unsupported type passed to output")
	case reflect.Array, reflect.Slice:
		buf := bytes.NewBufferString("[ ")

		for i := 0; i < r.Len(); i++ {
			buf.Write(output(r.Index(i)))
			buf.WriteString(" ")
		}

		buf.WriteString("]")

		return buf.Bytes()
	case reflect.Map:
		buf := bytes.NewBufferString("<<\n")

		for _, k := range r.MapKeys() {
			if k.Kind() != reflect.String {
				panic("key of map passed to output is not string")
			}
			buf.Write(output(name(k.String())))
			buf.WriteString(" ")
			buf.Write(output(r.MapIndex(k)))
			buf.WriteString("\n")
		}

		buf.WriteString(">>")

		return buf.Bytes()
	}

	return []byte("null")
}
开发者ID:mostafah,项目名称:pdf.go,代码行数:76,代码来源:output.go

示例15: reflectValue

func (e *encodeState) reflectValue(v reflect.Value) {
	if v == nil {
		e.WriteString("null")
		return
	}

	if j, ok := v.Interface().(Marshaler); ok {
		b, err := j.MarshalJSON()
		if err == nil {
			// copy JSON into buffer, checking validity.
			err = Compact(&e.Buffer, b)
		}
		if err != nil {
			e.error(&MarshalerError{v.Type(), err})
		}
		return
	}

	switch v := v.(type) {
	case *reflect.BoolValue:
		x := v.Get()
		if x {
			e.WriteString("true")
		} else {
			e.WriteString("false")
		}

	case *reflect.IntValue:
		e.WriteString(strconv.Itoa(v.Get()))
	case *reflect.Int8Value:
		e.WriteString(strconv.Itoa(int(v.Get())))
	case *reflect.Int16Value:
		e.WriteString(strconv.Itoa(int(v.Get())))
	case *reflect.Int32Value:
		e.WriteString(strconv.Itoa(int(v.Get())))
	case *reflect.Int64Value:
		e.WriteString(strconv.Itoa64(v.Get()))

	case *reflect.UintValue:
		e.WriteString(strconv.Uitoa(v.Get()))
	case *reflect.Uint8Value:
		e.WriteString(strconv.Uitoa(uint(v.Get())))
	case *reflect.Uint16Value:
		e.WriteString(strconv.Uitoa(uint(v.Get())))
	case *reflect.Uint32Value:
		e.WriteString(strconv.Uitoa(uint(v.Get())))
	case *reflect.Uint64Value:
		e.WriteString(strconv.Uitoa64(v.Get()))
	case *reflect.UintptrValue:
		e.WriteString(strconv.Uitoa64(uint64(v.Get())))

	case *reflect.FloatValue:
		e.WriteString(strconv.Ftoa(v.Get(), 'g', -1))
	case *reflect.Float32Value:
		e.WriteString(strconv.Ftoa32(v.Get(), 'g', -1))
	case *reflect.Float64Value:
		e.WriteString(strconv.Ftoa64(v.Get(), 'g', -1))

	case *reflect.StringValue:
		e.string(v.Get())

	case *reflect.StructValue:
		e.WriteByte('{')
		t := v.Type().(*reflect.StructType)
		n := v.NumField()
		for i := 0; i < n; i++ {
			if i > 0 {
				e.WriteByte(',')
			}
			f := t.Field(i)
			if f.Tag != "" {
				e.string(f.Tag)
			} else {
				e.string(f.Name)
			}
			e.WriteByte(':')
			e.reflectValue(v.Field(i))
		}
		e.WriteByte('}')

	case *reflect.MapValue:
		if _, ok := v.Type().(*reflect.MapType).Key().(*reflect.StringType); !ok {
			e.error(&UnsupportedTypeError{v.Type()})
		}
		if v.IsNil() {
			e.WriteString("null")
			break
		}
		e.WriteByte('{')
		var sv stringValues = v.Keys()
		sort.Sort(sv)
		for i, k := range sv {
			if i > 0 {
				e.WriteByte(',')
			}
			e.string(k.(*reflect.StringValue).Get())
			e.WriteByte(':')
			e.reflectValue(v.Elem(k))
		}
		e.WriteByte('}')
//.........这里部分代码省略.........
开发者ID:rapgamer,项目名称:golang-china,代码行数:101,代码来源:encode.go


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