Update docs to point to Git repository.
[hooke.git] / hooke / util / si.py
index ac3e633746571177bb1e8c2f83d214fc8704d8de..ddf319bac59402cd87eac41e004552397c2b5a43 100644 (file)
@@ -1,22 +1,19 @@
-# Copyright (C) 2010 Massimo Sandal <devicerandom@gmail.com>
-#                    Rolf Schmidt <rschmidt@alcor.concordia.ca>
-#                    W. Trevor King <wking@drexel.edu>
+# Copyright (C) 2010-2012 W. Trevor King <wking@drexel.edu>
 #
 # This file is part of Hooke.
 #
-# Hooke is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
+# Hooke is free software: you can redistribute it and/or modify it under the
+# terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option) any
+# later version.
 #
-# Hooke is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
-# Public License for more details.
+# Hooke is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
+# details.
 #
-# You should have received a copy of the GNU Lesser General Public
-# License along with Hooke.  If not, see
-# <http://www.gnu.org/licenses/>.
+# You should have received a copy of the GNU Lesser General Public License
+# along with Hooke.  If not, see <http://www.gnu.org/licenses/>.
 
 """Define functions for handling numbers in SI notation.
 
@@ -127,7 +124,11 @@ def ppSI(value, unit='', decimals=None, power=None, pad=False):
                 # 1 for ' ', 1 for '-', 3 for number, 1 for '.', and decimals.
                 pad = 6 + decimals
             format = lambda n: '%*.*f' % (pad, decimals, n)
-    return '%s %s%s' % (format(value / pow(10,power)), PREFIX[power], unit)
+    try:
+        prefix = ' '+PREFIX[power]
+    except KeyError:
+        prefix = 'e%d ' % power
+    return '%s%s%s' % (format(value / pow(10,power)), prefix, unit)
 
 
 def get_power(value):
@@ -178,7 +179,7 @@ def join_data_label(name, unit):
     >>> join_data_label('z piezo', 'm')
     'z piezo (m)'
     >>> join_data_label('deflection', 'N')
-    'deflection N'
+    'deflection (N)'
     """
     return '%s (%s)' % (name, unit)