Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
rym-util
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhengqiuyun
rym-util
Commits
f76e97a8
Commit
f76e97a8
authored
Nov 11, 2022
by
zhengqiuyun86
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
float精度计算
parent
954a4556
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
1 deletion
+28
-1
FloatUtil.go
util/FloatUtil.go
+28
-1
No files found.
util/FloatUtil.go
View file @
f76e97a8
package
util
import
"strconv"
import
(
"math/big"
"strconv"
)
//FormatFloat64 将多余的浮点格式化
func
FormatFloat64
(
f
float64
)
string
{
...
...
@@ -11,3 +14,27 @@ func FormatFloat64(f float64) string {
func
FormatFloat32
(
f
float32
)
string
{
return
strconv
.
FormatFloat
(
float64
(
f
),
'f'
,
-
1
,
32
)
}
// AddFloat64 精度加法 a+b
func
AddFloat64
(
a
*
float64
,
b
*
float64
)
*
float64
{
r
,
_
:=
new
(
big
.
Float
)
.
Add
(
new
(
big
.
Float
)
.
SetFloat64
(
*
a
),
new
(
big
.
Float
)
.
SetFloat64
(
*
b
))
.
Float64
()
return
&
r
}
// SubtractFloat64 精度减法 a-b
func
SubtractFloat64
(
a
*
float64
,
b
*
float64
)
*
float64
{
r
,
_
:=
new
(
big
.
Float
)
.
Sub
(
new
(
big
.
Float
)
.
SetFloat64
(
*
a
),
new
(
big
.
Float
)
.
SetFloat64
(
*
b
))
.
Float64
()
return
&
r
}
// MultiplyFloat64 精度乘法 axb
func
MultiplyFloat64
(
a
*
float64
,
b
*
float64
)
*
float64
{
r
,
_
:=
new
(
big
.
Float
)
.
Mul
(
new
(
big
.
Float
)
.
SetFloat64
(
*
a
),
new
(
big
.
Float
)
.
SetFloat64
(
*
b
))
.
Float64
()
return
&
r
}
// DivideFloat64 精度除法 a/b
func
DivideFloat64
(
a
*
float64
,
b
*
float64
)
*
float64
{
r
,
_
:=
new
(
big
.
Float
)
.
Quo
(
new
(
big
.
Float
)
.
SetFloat64
(
*
a
),
new
(
big
.
Float
)
.
SetFloat64
(
*
b
))
.
Float64
()
return
&
r
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment