On Wed, 26 Jul 2017, Summers, Peter wrote:
Ok, I'm not used to thinking in terms of %f & %g but your
explanation makes sense. To clarify, the '#' shouldn't be there,
right?
Well, it depends how you want numbers to appear: with the '#'
modifier, trailing zeros are printed to the specified precision,
without it they're not printed. When printing a matrix with 'g'
conversion, your probably want the '#' for the sake of uniformity.
<hansl, echo and output>
? printf "%#.5g\n", 1.234567
1.2346
? printf "%#.5g\n", 1.2
1.2000
? printf "%.5g\n", 1.2
1.2
</hansl>
Allin
> On Jul 26, 2017, at 5:38 PM, Allin Cottrell
<cottrell(a)wfu.edu> wrote:
>
>> On Wed, 26 Jul 2017, Summers, Peter wrote:
>>
>> Hi all,
>>
>> I've come across a typo on p. 80 in the user's guide. In
>> discussing how to access elements of an array, there's the
>> following example:
>>
>> <verbatim>
>> # for M an array of matrices
>> printf "\n%#12.5\n", M[1]
>> </verbatim>
>>
>> The second line should be
>> printf "\n%12.5f\n", M[1]
>
> Thanks, Peter. There was a typo, but actually what we had in mind
> in this case was
>
> printf "\n%#12.5g\n", M[1]
>
> The conversion 'g' for floating-point numbers means "use
> scientific notation if necessary" (i.e. for very big or very
> small numbers), and the '#' modifier means, print any trailing
> zeros to the given precision.