Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
search_server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
a8d4746d
authored
Jul 06, 2020
by
huangchengyi
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
1.0
parent
caaf69a1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
0 deletions
test/test4.go
test/test4.go
0 → 100644
View file @
a8d4746d
package
main
import
(
"fmt"
"strconv"
)
func
main
()
{
var
a
,
b
,
c
float64
a
=
1.69
*
100
b
=
1.7
*
10
c
=
a
*
b
/
(
100
*
10
)
//正确结果2.873
fmt
.
Println
(
c
)
//fmt.Println(fmt.Sprintf("%.2f",c))
//fmt.Println(FloatRound(c,2))
}
// 截取小数位数
func
FloatRound
(
f
float64
,
n
int
)
float64
{
format
:=
"%."
+
strconv
.
Itoa
(
n
)
+
"f"
//fmt.Println(format)
res
,
_
:=
strconv
.
ParseFloat
(
fmt
.
Sprintf
(
format
,
f
),
64
)
return
res
}
\ No newline at end of file
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