Print number in engineering format
        Posted  
        
            by 
                jmurrayufo
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by jmurrayufo
        
        
        
        Published on 2012-09-07T03:00:21Z
        Indexed on 
            2012/09/07
            3:38 UTC
        
        
        Read the original article
        Hit count: 170
        
I am trying to print a number into engineering format with python, but I cannot seem to get it to work. The syntax SEEMS simple enough, but it just doesn't work.
>>> import decimal 
>>> x = decimal.Decimal(1000000)
>>> print x
1000000
>>>> print x.to_eng_string() 
1000000
I cannot figure out why this is. The two values are not equal (one is a string, the other is an int). Setting various contexts in decimal doesn't seem to help either. Any clues or ideas?
© Stack Overflow or respective owner