1 Star 0 Fork 0

muicx / quickfix

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
fix_float.go 779 Bytes
一键复制 编辑 原始数据 按行查看 历史
Chris Busbey 提交于 2016-06-07 08:19 . Misc field type refactoring (#145)
package quickfix
import (
"fmt"
"strconv"
)
//FIXFloat is a FIX Float Value, implements FieldValue
type FIXFloat float64
//Float64 converts the FIXFloat value to float64
func (f FIXFloat) Float64() float64 { return float64(f) }
func (f *FIXFloat) Read(bytes []byte) error {
val, err := strconv.ParseFloat(string(bytes), 64)
if err != nil {
return err
}
//strconv allows values like "+100.00", which is not allowed for FIX float types
for _, b := range bytes {
if b != '.' && b != '-' && !isDecimal(b) {
return fmt.Errorf("invalid value %v", string(bytes))
}
}
*f = FIXFloat(val)
return err
}
func (f FIXFloat) Write() []byte {
return []byte(strconv.FormatFloat(float64(f), 'f', -1, 64))
}
func isDecimal(b byte) bool {
return '0' <= b && b <= '9'
}
Go
1
https://gitee.com/bradhuang/quickfixgo.git
git@gitee.com:bradhuang/quickfixgo.git
bradhuang
quickfixgo
quickfix
dependabot/go_modules/github.com/mattn/go-sqlite3-1.14.9

搜索帮助