@@ -202,17 +202,9 @@ function _pfmt_f(out::IO, fs::FormatSpec, x::AbstractFloat)
202
202
end
203
203
end
204
204
205
- function _pfmt_floate (out:: IO , sch:: Char , zs:: Integer , u:: Real , prec:: Int , e:: Int , ec:: Char )
205
+ function _pfmt_floate (out:: IO , sch:: Char , zs:: Integer , u:: Real , prec:: Int , e:: Integer , ec:: Char )
206
206
intv = trunc (Integer,u)
207
207
decv = u - intv
208
- if round (Integer, decv * exp10 (prec)) == exp10 (prec)
209
- intv += 1
210
- if intv == 10
211
- intv = 1
212
- e += 1
213
- end
214
- decv = 0.
215
- end
216
208
_pfmt_float (out, sch, zs, intv, decv, prec)
217
209
write (out, ec)
218
210
if e >= 0
@@ -221,9 +213,10 @@ function _pfmt_floate(out::IO, sch::Char, zs::Integer, u::Real, prec::Int, e::In
221
213
write (out, ' -' )
222
214
e = - e
223
215
end
224
- (e1, e2) = divrem (e, 10 )
225
- write (out, Char (' 0' + e1))
226
- write (out, Char (' 0' + e2))
216
+ if e < 10
217
+ write (out, ' 0' )
218
+ end
219
+ _pfmt_intdigits (out, e, _Dec ())
227
220
end
228
221
229
222
@@ -235,15 +228,21 @@ function _pfmt_e(out::IO, fs::FormatSpec, x::AbstractFloat)
235
228
e = 0
236
229
u = zero (x)
237
230
else
238
- e = floor (Integer,log10 (ax)) # exponent
239
- u = ax / exp10 (e) # significand
231
+ e = floor (Integer, log10 (ax))
232
+ scale = exp10 (- e + fs. prec)
233
+ rax = round (ax * scale) / scale
234
+ e = floor (Integer, log10 (rax)) # exponent
235
+ u = rax / exp10 (e) # significand
240
236
end
241
237
242
238
# calculate length
243
239
xlen = 6 + fs. prec
240
+ if abs (e) > 99
241
+ xlen += _ndigits (abs (e), _Dec ()) - 2
242
+ end
244
243
if sch != ' \0 '
245
244
xlen += 1
246
- end
245
+ end
247
246
248
247
# print
249
248
ec = isupper (fs. typ) ? ' E' : ' e'
0 commit comments