Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
U
uni-pdtravel
Project
Project
Details
Activity
Releases
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
panyongping
uni-pdtravel
Commits
4bd10ec2
Commit
4bd10ec2
authored
Aug 15, 2022
by
潘永坪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
公共方法增加
parent
745d7900
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
0 deletions
+22
-0
main.js
main.js
+22
-0
No files found.
main.js
View file @
4bd10ec2
...
@@ -16,4 +16,26 @@ const app = new Vue({
...
@@ -16,4 +16,26 @@ const app = new Vue({
...
App
...
App
})
})
app
.
$mount
()
app
.
$mount
()
//保留小数方法,第一个参数是需要保留的数字,第二个参数是需要保留几位小数
function
toFixed
(
number
,
m
)
{
if
(
typeof
number
!==
'number'
)
{
throw
new
Error
(
"number不是数字"
);
}
let
result
=
Math
.
round
(
Math
.
pow
(
10
,
m
)
*
number
)
/
Math
.
pow
(
10
,
m
);
result
=
String
(
result
);
if
(
result
.
indexOf
(
"."
)
==
-
1
)
{
if
(
m
!=
0
){
result
+=
"."
;
result
+=
new
Array
(
m
+
1
).
join
(
'0'
);
}
}
else
{
let
arr
=
result
.
split
(
'.'
);
if
(
arr
[
1
].
length
<
m
)
{
arr
[
1
]
+=
new
Array
(
m
-
arr
[
1
].
length
+
1
).
join
(
'0'
)
}
result
=
arr
.
join
(
'.'
)
}
return
parseFloat
(
result
)
}
Vue
.
prototype
.
$toFixed
=
toFixed
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