Exemplo n.º 1
0
func EncodeStringNumber(value string) ([]byte, error) {
	if strings.Count(value, ".") > 0 {
		number, ok := big.NewDecimal(value)
		if !ok {
			return nil, Error("couldn't create a big.Decimal representation of " + value)
		}
		return EncodeBigDecimal(number), nil
	}
	number, ok := new(big.Int).SetString(value, 10)
	if !ok {
		return nil, Error("couldn't create an big.Int representation of " + value)
	}
	return EncodeBigInt(number), nil
}
Exemplo n.º 2
0
Arquivo: argo.go Projeto: nuin/ampify
func WriteNumber(value string, buffer *bytes.Buffer) os.Error {
	if strings.Count(value, ".") > 0 {
		number, ok := big.NewDecimal(value)
		if !ok {
			return EncodingError("Couldn't create a Decimal representation of " + value)
		}
		WriteDecimal(number, buffer)
		return nil
	}
	number, ok := new(big.Int).SetString(value, 10)
	if !ok {
		return EncodingError("Couldn't create an Int representation of " + value)
	}
	WriteBigInt(number, buffer)
	return nil
}
Exemplo n.º 3
0
func decimal(value string) *big.Decimal {
	dec, _ := big.NewDecimal(value)
	return dec
}