#NEWLINE# def format_crypto_units( input_quantity , input_type , output_type , coin_symbol = None , print_cs = False , safe_trimming = False , round_digits = 0 ) : #NEWLINE# #INDENT# '\n    Take an input like 11002343 satoshis and convert it to another unit (e.g. BTC) and format it with appropriate units\n\n    if coin_symbol is supplied and print_cs == True then the units will be added (e.g. BTC or satoshis)\n\n    Smart trimming gets rid of trailing 0s in the decimal place, except for satoshis (irrelevant) and bits (always two decimals points).\n    It also preserves one decimal place in the case of 1.0 to show significant figures.\n    It is stil technically correct and reversible.\n\n    Smart rounding performs a rounding operation (so it is techincally not the correct number and is not reversible).\n    The number of decimals to round by is a function of the output_type\n\n    Requires python >= 2.7\n    ' #NEWLINE# assert ( input_type in UNIT_CHOICES ) , input_type #NEWLINE# assert ( output_type in UNIT_CHOICES ) , output_type #NEWLINE# if print_cs : #NEWLINE# #INDENT# assert is_valid_coin_symbol ( coin_symbol = coin_symbol ) , coin_symbol #NEWLINE# #UNINDENT# assert ( type ( round_digits ) is int ) #NEWLINE# satoshis_float = to_satoshis ( input_quantity = input_quantity , input_type = input_type ) #NEWLINE# if round_digits : #NEWLINE# #INDENT# satoshis_float = round ( satoshis_float , ( ( - 1 ) * round_digits ) ) #NEWLINE# #UNINDENT# output_quantity = from_satoshis ( input_satoshis = satoshis_float , output_type = output_type ) #NEWLINE# if ( ( output_type == 'bit' ) and ( round_digits >= 2 ) ) : #NEWLINE# #INDENT# pass #NEWLINE# output_quantity_formatted = format_output ( num = output_quantity , output_type = 'satoshi' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# output_quantity_formatted = format_output ( num = output_quantity , output_type = output_type ) #NEWLINE# #UNINDENT# if ( safe_trimming and ( output_type not in ( 'satoshi' , 'bit' ) ) ) : #NEWLINE# #INDENT# output_quantity_formatted = safe_trim ( qty_as_string = output_quantity_formatted ) #NEWLINE# #UNINDENT# if print_cs : #NEWLINE# #INDENT# curr_symbol = get_curr_symbol ( coin_symbol = coin_symbol , output_type = output_type ) #NEWLINE# output_quantity_formatted += ( ' %s' % safe_trimming ) #NEWLINE# #UNINDENT# return output_quantity_formatted