Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
taobao-mini-template
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
2
Issues
2
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
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
qinhaitao
taobao-mini-template
Commits
5b389c06
Commit
5b389c06
authored
Sep 14, 2020
by
李硕
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加方法
parent
140b1327
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
1 deletion
+62
-1
utils.js
server/duiba/utils/utils.js
+62
-1
No files found.
server/duiba/utils/utils.js
View file @
5b389c06
...
@@ -120,6 +120,23 @@ const formatTime = function dateFormat(thisDate, fmt = "yyyy-MM-dd hh:mm:ss") {
...
@@ -120,6 +120,23 @@ const formatTime = function dateFormat(thisDate, fmt = "yyyy-MM-dd hh:mm:ss") {
fmt
=
fmt
.
replace
(
RegExp
.
$1
,
(
RegExp
.
$1
.
length
==
1
)
?
(
o
[
k
])
:
((
"00"
+
o
[
k
]).
substr
((
""
+
o
[
k
]).
length
)));
fmt
=
fmt
.
replace
(
RegExp
.
$1
,
(
RegExp
.
$1
.
length
==
1
)
?
(
o
[
k
])
:
((
"00"
+
o
[
k
]).
substr
((
""
+
o
[
k
]).
length
)));
return
fmt
;
return
fmt
;
}
}
//时间戳转为>2020/09/14
const
formatDate
=
function
(
secs
)
{
//123456789 -->
var
t
=
new
Date
(
secs
);
var
year
=
t
.
getFullYear
();
var
month
=
t
.
getMonth
()
+
1
;
if
(
month
<
10
)
{
month
=
'0'
+
month
};
var
date
=
t
.
getDate
();
if
(
date
<
10
)
{
date
=
'0'
+
date
};
// var hour = t.getHours()
// if (hour < 10) { hour = '0' + hour }
// var minute = t.getMinutes()
// if (minute < 10) { minute = '0' + minute }
// var second = t.getSeconds()
// if (second < 10) { second = '0' + second }
return
year
+
'/'
+
month
+
'/'
+
date
;
// + hour + ':' + minute + ':' + second
};
function
MathRand
()
{
function
MathRand
()
{
var
Num
=
""
;
var
Num
=
""
;
...
@@ -128,6 +145,46 @@ function MathRand() {
...
@@ -128,6 +145,46 @@ function MathRand() {
}
}
return
Num
;
return
Num
;
}
}
// 解决小数相加精度问题
function
addFloat
(
num1
,
num2
)
{
var
r1
,
r2
,
m
;
r1
=
num1
.
toString
().
split
(
"."
)[
1
]
?
num1
.
toString
().
split
(
"."
)[
1
].
length
:
0
;
r2
=
num2
.
toString
().
split
(
"."
)[
1
]
?
num2
.
toString
().
split
(
"."
)[
1
].
length
:
0
;
m
=
Math
.
pow
(
10
,
Math
.
max
(
r1
,
r2
));
return
(
num1
*
m
+
num2
*
m
)
/
m
;
}
// 小数相除
const
accMul
=
function
(
arg1
,
arg2
)
{
var
m
=
0
,
s1
=
arg1
.
toString
();
s2
=
arg2
.
toString
();
try
{
m
+=
s1
.
split
(
"."
)[
1
].
length
;
}
catch
(
e
)
{
}
try
{
m
+=
s2
.
split
(
"."
)[
1
].
length
;
}
catch
(
e
)
{
}
return
(
(
Number
(
s1
.
replace
(
"."
,
""
))
*
Number
(
s2
.
replace
(
"."
,
""
)))
/
Math
.
pow
(
10
,
m
)
);
};
// 小数相乘
const
signFigures
=
function
(
num
,
rank
=
6
)
{
if
(
!
num
)
return
0
;
const
sign
=
num
/
Math
.
abs
(
num
);
const
number
=
num
*
sign
;
const
temp
=
rank
-
1
-
Math
.
floor
(
Math
.
log10
(
number
));
let
ans
;
if
(
temp
>
0
)
{
ans
=
parseFloat
(
number
.
toFixed
(
temp
));
}
else
if
(
temp
<
0
)
{
ans
=
Math
.
round
(
number
/
Math
.
pow
(
10
,
temp
))
*
temp
;
}
else
{
ans
=
Math
.
round
(
number
);
}
return
ans
*
sign
;
};
module
.
exports
=
{
module
.
exports
=
{
loginfo
,
loginfo
,
...
@@ -135,5 +192,9 @@ module.exports = {
...
@@ -135,5 +192,9 @@ module.exports = {
passUrlList
,
passUrlList
,
urlCheck
,
urlCheck
,
isNewDay
,
isNewDay
,
formatTime
formatTime
,
addFloat
,
formatDate
,
accMul
,
signFigures
}
}
\ 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