#333 Optionally remove trailing zeros in gprintf

None
closed-rejected
nobody
None
5
2014-06-18
2012-06-18
guu-sama
No

In help file one can find an example:
set format y "%s %cg"; set ytic(12345) # "12.345 kg"
on 4.6.0 (4.6.2 has same problem) under Win7 x64 Home Basic (and also under Win7 x64 Prof. the same problem) the result will be "12.345000 kg" since %s format specifier doesnt work properly. I dont know why, but '%s' specifier forces gnuplot to show six digits after decimal point.

Discussion

1 2 > >> (Page 1 of 2)
  • Ethan Merritt
    Ethan Merritt
    2012-06-18

    If you want to limit the number of decimal places, you should put that in the format:
    set format y "%.3s %cg"
    This is true in general for C-language style formats.

     
  • Ethan Merritt
    Ethan Merritt
    2012-06-18

    • status: open --> open-works-for-me
     
  • guu-sama
    guu-sama
    2012-06-18

    simple exmple

     
    Attachments
  • guu-sama
    guu-sama
    2012-06-18

    Dear sfeam,
    1. It is clear, that format spec '%s' works in wrong way (see example from help, mentioned above). So it is a bug, though, may be OS depended...
    2. The problem is not to limit length of number of digits, i just want to print only MEANING digits. In other words, zeros on the end of number is meaningless. As example, '%g' works properly and doesnt print meaningless zeros on the end.

    One more example.
    I plot waveform from LeCroy Osc. The t-range is from 0 to 10 s with time-resolution 50 ns. If i select xrange (or time period) from 9.9999 s to 10 s in order to see very short pulses, i will get xtics set with format spec '%.3s %cs' ("9.999 s" "9.999 s" "9.999 s" "9.999 s" "9.999 s" "9.999 s" "9.999 s").

     
  • Ethan Merritt
    Ethan Merritt
    2012-06-18

    Only you know the correct number of significant digits, so you will have to tell the program. But it is not correct that "zeros on the end of a number are meaningless". If your measurement is accurate to 3 digits, then those three digits are significant even if they happen to be zero.

    If you want a precision of nanoseconds on an axis marked in seconds, clearly you need more than 3 digits.

     
  • guu-sama
    guu-sama
    2012-06-19

    Dear sfeam,
    thanks for information, but i have PhD in Physics, so i do know about measurements precision.
    The problem is not in measurements precision, but in gnuplot. In the 3rd time, here is an example:
    From gnupolot help-file: set format y "%s %cg"; set ytic(12345) # "12.345 kg"
    In real life (Win7 to be more correct, v. 4.6.0, 4.4.2): "%s %cg"; set ytic(12345) # "12.345000 kg"

    Dear developers, if u will have a free time for it, please, consider described problem. It is a great problem for me and for others :(

     
  • This is not a bug in gnuplot's behaviour. gnuplot treats your specified ytic as a floating point number and has no notion of precision other than the one you specify. Otherwise the C library chooses its default, which happens to be 6 digits. This behaviour has nothing to do with the platform and is the same on Linux as on Windows.
    Having said that, the docs might need some clarification in this respect.

    Please note that the %g specifier is the only one that actually strips trailing zeros. This is a feature of the C library. If you want that, you could use "% g s" as format for your LeCroy example.

    Moving this to "Feature Requests": Add support for an additional modifier in grpintf() which would cause it to remove trailing zeroes.

     
    • labels: 102070 -->
    • summary: Format spec problems on Win7 --> Optionally remove trailing zeros in gprintf
    • status: open-works-for-me --> open
     
  • guu-sama
    guu-sama
    2012-06-19

    Dear markisch,
    thank for ur answer. For sci graph tics like "80 us" ('%s %cs') is better than "8e-005 s" ('% g s') is better. But '%s %cs' gives 80.000000 us that is rather ugly unfortunately. It is strange, that %g manages trailing zeros, but %s doesnt.

     
  • Petr Mikulik
    Petr Mikulik
    2012-06-19

    > Add support for an additional modifier in gprintf() which would
    > cause it to remove trailing zeroes.

    \What about using _ as a specifier option would format the number with %g? I.e. "%_s", "%_l" etc.

     
1 2 > >> (Page 1 of 2)