@@ -7,22 +7,23 @@ import _ from 'lodash';
7
7
8
8
const { AV_SCAN_SCORER_REVIEW_TYPE_ID } = CONFIG ;
9
9
10
- function round ( num , decimal ) {
11
- if ( _ . isNaN ( num ) ) {
12
- return 0 ;
13
- }
14
- const p1 = 10 ** ( decimal + 1 ) ;
15
- const p2 = 10 ** decimal ;
16
- return Math . round ( num * p1 / 10 ) / p2 ;
10
+ function removeDecimal ( num ) {
11
+ const re = new RegExp ( '^-?\\d+' ) ;
12
+ return num . toString ( ) . match ( re ) [ 0 ] ;
17
13
}
18
14
19
- function removeDecimal ( num , decimal ) {
20
- return num < 0 ? ( ( num % decimal ) - decimal ) % decimal : ( ( num % decimal ) + decimal ) % decimal ;
15
+ function toAcurateFixed ( num , decimal ) {
16
+ const re = new RegExp ( `^-?\\d+(?:.\\d{0,${ ( decimal - 1 ) } })?` ) ;
17
+ return num . toString ( ) . match ( re ) [ 0 ] ;
21
18
}
22
19
23
20
function toFixed ( num , decimal ) {
24
- const result = _ . toFinite ( round ( num , decimal ) . toFixed ( decimal ) ) ;
25
- const integerResult = _ . toFinite ( removeDecimal ( result , decimal ) ) ;
21
+ if ( _ . isNaN ( parseFloat ( num ) ) ) return num ;
22
+ num = parseFloat ( num ) ;
23
+
24
+ const result = _ . toFinite ( toAcurateFixed ( num , decimal ) ) ;
25
+ const integerResult = _ . toFinite ( removeDecimal ( num ) ) ;
26
+
26
27
if ( _ . isInteger ( integerResult ) ) {
27
28
return integerResult ;
28
29
}
@@ -141,8 +142,8 @@ export function processMMSubmissions(submissions, resources, registrants) {
141
142
return dateB - dateA ;
142
143
} ) ;
143
144
144
- const provisionalScore = toFixed ( parseFloat ( _ . get ( validReviews , '[0].score' , '-' ) ) , 5 ) ;
145
- const finalScore = toFixed ( parseFloat ( _ . get ( submission , 'reviewSummation[0].aggregateScore' , '-' ) ) , 5 ) ;
145
+ const provisionalScore = toFixed ( _ . get ( validReviews , '[0].score' , '-' ) , 5 ) ;
146
+ const finalScore = toFixed ( _ . get ( submission , 'reviewSummation[0].aggregateScore' , '-' ) , 5 ) ;
146
147
147
148
data [ memberHandle ] . push ( {
148
149
submissionId : submission . id ,
0 commit comments