From 7fca3356f84daf6fc182cdb904a341b3c6f21398 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=85=89=E6=98=A5?= Date: Thu, 26 May 2022 17:56:14 +0800 Subject: [PATCH] - init --- .drone.yml | 17 +++++++++++++++++ .gitignore | 9 +++++++++ go.mod | 3 +++ goint64.go | 31 +++++++++++++++++++++++++++++++ goint64_test.go | 19 +++++++++++++++++++ version.go | 3 +++ version_test.go | 7 +++++++ 7 files changed, 89 insertions(+) create mode 100644 .drone.yml create mode 100644 .gitignore create mode 100644 go.mod create mode 100644 goint64.go create mode 100644 goint64_test.go create mode 100644 version.go create mode 100644 version_test.go diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..c56c479 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,17 @@ +kind: pipeline +type: docker +name: clone + +steps: + - name: Test + image: golang:1.18 + commands: + - go env -w GO111MODULE=on + - go env -w GOPROXY=https://goproxy.cn,direct + - go test -v ./... + - name: Benchmark + image: golang:1.18 + commands: + - go env -w GO111MODULE=on + - go env -w GOPROXY=https://goproxy.cn,direct + - go test -bench=. -benchmem \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4794692 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +.env +.git +.svn +.idea +.vscode +*.log +goinit.sh +gomod.sh +/vendor/ \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..27c8c6b --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module go.dtapp.net/goint64 + +go 1.18 diff --git a/goint64.go b/goint64.go new file mode 100644 index 0000000..dfee53e --- /dev/null +++ b/goint64.go @@ -0,0 +1,31 @@ +package goint64 + +import ( + "math" + "strconv" +) + +// ToFloat64 int64到float64 +func ToFloat64(n int64) float64 { + return float64(n) / math.Pow10(0) +} + +// ToUnwrap 将int64恢复成正常的float64 +func ToUnwrap(num int64, retain int) float64 { + return float64(num) / math.Pow10(retain) +} + +// ToUnwrapToInt64 精准int64 +func ToUnwrapToInt64(num int64, retain int) int64 { + return int64(ToUnwrap(num, retain)) +} + +// ToFloat64NewWiFi 返回float64 +func ToFloat64NewWiFi(num int64) float64 { + return float64(num / 100) +} + +// ToString int到string +func ToString(n int64) string { + return strconv.FormatInt(n, 10) +} diff --git a/goint64_test.go b/goint64_test.go new file mode 100644 index 0000000..a91ef56 --- /dev/null +++ b/goint64_test.go @@ -0,0 +1,19 @@ +package goint64 + +import "testing" + +func TestToFloat64(t *testing.T) { + t.Log(ToFloat64(1444)) +} + +func TestToUnwrap(t *testing.T) { + t.Log(ToUnwrap(1444, 2)) +} + +func TestToUnwrapToInt64(t *testing.T) { + t.Log(ToUnwrapToInt64(1444, 2)) +} + +func TestToFloat64NewWiFi(t *testing.T) { + t.Log(ToFloat64NewWiFi(1444)) +} diff --git a/version.go b/version.go new file mode 100644 index 0000000..0014478 --- /dev/null +++ b/version.go @@ -0,0 +1,3 @@ +package goint64 + +const Version = "1.0.0" diff --git a/version_test.go b/version_test.go new file mode 100644 index 0000000..9cbaba3 --- /dev/null +++ b/version_test.go @@ -0,0 +1,7 @@ +package goint64 + +import "testing" + +func TestVersion(t *testing.T) { + t.Log(Version) +}