File tree Expand file tree Collapse file tree 3 files changed +16
-3
lines changed
Expand file tree Collapse file tree 3 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,19 @@ const servicesDir = path.join(__dirname, 'services');
1414let fiatFetched = false ;
1515let cryptoFetched = false ;
1616
17+ function truncate_number ( value , decimals ) {
18+ const valueStr = value . toString ( ) ;
19+ const dotIndex = valueStr . indexOf ( '.' ) ;
20+ if ( dotIndex === - 1 ) return valueStr ;
21+ const desiredLength = dotIndex + decimals + 1 ;
22+ let truncated = valueStr . slice ( 0 , desiredLength ) ;
23+
24+ if ( parseFloat ( truncated ) === 0 && value > 0 ) {
25+ return valueStr ;
26+ }
27+ return truncated ;
28+ }
29+
1730async function main ( ) {
1831 if ( ! config [ 'schedule' ] )
1932 throw new Error ( 'The crontab schedule is not set.' ) ;
@@ -76,7 +89,7 @@ async function main() {
7689 [
7790 currency . from_currency ,
7891 currency . conv_currency ,
79- currency . rate ,
92+ truncate_number ( currency . rate , 30 ) ,
8093 currency . date ,
8194 ] ,
8295 ) ;
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ const currencySchema = Joi.object({
1717 'date.base' : 'date must be a valid ISO date' ,
1818 'any.required' : 'date is required' ,
1919 } ) ,
20- rate : Joi . number ( ) . precision ( 30 ) . positive ( ) . required ( ) . messages ( {
20+ rate : Joi . number ( ) . positive ( ) . required ( ) . messages ( {
2121 'number.base' : 'rate must be a number' ,
2222 'number.positive' : 'rate must be a positive number' ,
2323 'number.precision' : 'rate must have no more than 6 decimal places' ,
Original file line number Diff line number Diff line change 11CREATE TABLE IF NOT EXISTS currency(
22 from_currency TEXT NOT NULL ,
33 conv_currency TEXT NOT NULL ,
4- rate NUMERIC ( 30 ) NOT NULL ,
4+ rate NUMERIC NOT NULL ,
55 date DATE NOT NULL
66);
77
You can’t perform that action at this time.
0 commit comments