@@ -200,7 +200,9 @@ function print_fixed(out, precision, pt, ndigits, trailingzeros=true)
200
200
write (out, ' 0' )
201
201
ndigits += 1
202
202
end
203
- write (out, trailingzeros ? ' .' : ' ' )
203
+ if trailingzeros
204
+ write (out, ' .' )
205
+ end
204
206
else # 0 < pt < ndigits
205
207
# dd.dd0000
206
208
ndigits -= pt
@@ -411,7 +413,7 @@ function gen_e(flags::ASCIIString, width::Int, precision::Int, c::Char, inside_g
411
413
blk = ifblk. args[2 ]
412
414
push! (blk. args, :((len, pt, neg) = args))
413
415
push! (blk. args, :(exp = pt- 1 ))
414
- expmark = c == ' E ' ? " E" : " e"
416
+ expmark = isupper (c) ? " E" : " e"
415
417
if precision== 0 && ' #' in flags
416
418
expmark = string (" ." ,expmark)
417
419
end
@@ -680,6 +682,17 @@ function gen_p(flags::ASCIIString, width::Int, precision::Int, c::Char)
680
682
end
681
683
682
684
function gen_g (flags:: ASCIIString , width:: Int , precision:: Int , c:: Char )
685
+ # print to fixed trailing precision
686
+ # [g]: lower case e on scientific
687
+ # [G]: Upper case e on scientific
688
+ #
689
+ # flags
690
+ # (#): always print a decimal point
691
+ # (0): pad left with zeros
692
+ # (-): left justify
693
+ # ( ): precede non-negative values with " "
694
+ # (+): precede non-negative values with "+"
695
+ #
683
696
x, ex, blk = special_handler (flags,width)
684
697
if precision < 0 ; precision = 6 ; end
685
698
ndigits = min (precision+ 1 ,length (DIGITS)- 1 )
@@ -709,14 +722,9 @@ function gen_g(flags::ASCIIString, width::Int, precision::Int, c::Char)
709
722
push! (blk. args, :(width = $ width))
710
723
# need to compute value before left-padding since trailing zeros are elided
711
724
push! (blk. args, :(tmpout = IOBuffer ()))
712
- push! (blk. args, :(if fprec > 0
713
- print_fixed (tmpout,fprec,pt,len,$ (' #' in flags))
714
- else
715
- write (tmpout, pointer (DIGITS), len)
716
- while pt >= (len+= 1 ) write (tmpout,' 0' ) end
717
- end ))
725
+ push! (blk. args, :(print_fixed (tmpout,fprec,pt,len,$ (' #' in flags))))
718
726
push! (blk. args, :(tmpstr = takebuf_string (tmpout)))
719
- push! (blk. args, :(if fprec > 0 width -= length (tmpstr); end ))
727
+ push! (blk. args, :(width -= length (tmpstr)))
720
728
if ' +' in flags || ' ' in flags
721
729
push! (blk. args, :(width -= 1 ))
722
730
else
0 commit comments