@@ -7,22 +7,23 @@ import _ from 'lodash';
77
88const { AV_SCAN_SCORER_REVIEW_TYPE_ID } = CONFIG ;
99
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 ] ;
1713}
1814
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 ] ;
2118}
2219
2320function 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+
2627 if ( _ . isInteger ( integerResult ) ) {
2728 return integerResult ;
2829 }
@@ -141,8 +142,8 @@ export function processMMSubmissions(submissions, resources, registrants) {
141142 return dateB - dateA ;
142143 } ) ;
143144
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 ) ;
146147
147148 data [ memberHandle ] . push ( {
148149 submissionId : submission . id ,
0 commit comments