Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 86f505f

Browse files
committed
more fixes to mlab/excel formatters
svn path=/trunk/matplotlib/; revision=6182
1 parent c0c429a commit 86f505f

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

lib/matplotlib/mlab.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2181,7 +2181,7 @@ def __init__(self, fmt):
21812181

21822182
def tostr(self, x):
21832183
if x is None: return 'None'
2184-
return (self.fmt%self.toval(x)).rstrip('.')
2184+
return self.fmt%self.toval(x)
21852185

21862186

21872187

lib/mpl_toolkits/exceltools.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,11 @@ def xlformat_factory(format):
4141
xlstyle.num_format_str = '0.%s%%;[RED]-0.%s%%'%(zeros, zeros)
4242
format.scale = 1.
4343
elif isinstance(format, mlab.FormatFloat):
44-
zeros = ''.join(['0']*format.precision)
45-
xlstyle.num_format_str = '#,##0.%s;[RED]-#,##0.%s'%(zeros, zeros)
44+
if format.precision>0:
45+
zeros = ''.join(['0']*format.precision)
46+
xlstyle.num_format_str = '#,##0.%s;[RED]-#,##0.%s'%(zeros, zeros)
47+
else:
48+
xlstyle.num_format_str = '#,##;[RED]-#,##'
4649
elif isinstance(format, mlab.FormatInt):
4750
xlstyle.num_format_str = '#,##;[RED]-#,##'
4851
else:
@@ -99,11 +102,11 @@ def rec2excel(r, ws, formatd=None, rownum=0, colnum=0, nanstr='NaN', infstr='Inf
99102

100103
ind = np.arange(len(r.dtype.names))
101104
for row in r:
102-
#print 'row',
105+
103106
for i in ind:
104107
val = row[i]
105108
format = formats[i]
106-
109+
val = format.toval(val)
107110
if mlab.safe_isnan(val):
108111
ws.write(rownum, colnum+i, nanstr)
109112
elif mlab.safe_isinf(val):
@@ -112,11 +115,8 @@ def rec2excel(r, ws, formatd=None, rownum=0, colnum=0, nanstr='NaN', infstr='Inf
112115
else: s = '-%s'%infstr
113116
ws.write(rownum, colnum+i, s)
114117
elif format.xlstyle is None:
115-
val = format.toval(val)
116118
ws.write(rownum, colnum+i, val)
117119
else:
118-
val = format.toval(val)
119-
#print (i, r.dtype.names[i], val, format.toval(val)),
120120
ws.write(rownum, colnum+i, val, format.xlstyle)
121121
rownum += 1
122122

0 commit comments

Comments
 (0)