Commit c547242 1 parent 61b990b commit c547242 Copy full SHA for c547242
File tree 1 file changed +16
-2
lines changed
1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change 203
203
}
204
204
205
205
206
- function fmtDecimal ( n ) {
207
- return n . toLocaleString ( undefined , { minimumFractionDigits : 2 , maximumFractionDigits : 2 } ) ;
206
+ function fmtDecimal ( num ) {
207
+ // Multiply by 1000 to shift the decimal point
208
+ const shifted = Math . round ( num * 1000 ) ;
209
+
210
+ // Extract the first two decimal places
211
+ const wholePart = Math . floor ( shifted / 10 ) ; // Get the whole number part
212
+ const decimalPart = shifted % 10 ; // Get the third decimal place
213
+
214
+ // If the third decimal place is greater than 1, add it to the second decimal place
215
+ if ( decimalPart > 1 ) {
216
+ newNum = ( wholePart + 1 ) / 100 ; // Add 1 to the second decimal place
217
+ } else {
218
+ newNum = wholePart / 100 ; // Just return the number with two decimal places
219
+ }
220
+
221
+ return newNum . toLocaleString ( undefined , { minimumFractionDigits : 2 , maximumFractionDigits : 2 } ) ;
208
222
}
209
223
210
224
You can’t perform that action at this time.
0 commit comments