export function megaNumber ( ) { return ( n , fractionSize ) : string => { if ( n === null ) { return null ; } if ( n === 0 ) { return '0' ; } if ( ! fractionSize || fractionSize < 0 ) { fractionSize = 1 ; } var abs = Math . abs ( n ) ; var rounder = Math . pow ( 10 , fractionSize ) ; var isNegative = n < 0 ; var key = '' ; var powers = [ { key : 'Q' , value : Math . pow ( 10 , 15 ) } , { key : 'T' , value : Math . pow ( 10 , 12 ) } , { key : 'B' , value : Math . pow ( 10 , 9 ) } , { key : 'M' , value : Math . pow ( 10 , 6 ) } , { key : 'K' , value : 1000 } ] ; for ( var i = 0 ; i < powers . length ; i ++ ) { var reduced = abs / powers [ i ] . value ; reduced = Math . round ( reduced * rounder ) / rounder ; if ( reduced >= 1 ) { abs = reduced ; key = powers [ i ] . key ; break ; } } return ( isNegative ? '-' : '' ) + abs + key ; } ; } ;