import { Decimal } from 'decimal.js' ; import { ValueTransformer } from 'typeorm' ; export const DecimalTransformer = ( decimalPlaces = 2 ) : ValueTransformer => ( { to ( value ) { if ( ! value ) return ; return value . toFixed ( decimalPlaces ) ; } , from ( value ) { return new Decimal ( value ) ; } , } ) ;