Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Trailing zero

    Dear all, I am struggling with an apparently easy issue.

    I would like to add to my graph the trailing 0 of the values showed. For instance, in the image I attach I would like to have .10 instead of .1. I guess it is related to the command -format-, but I was not able to specify it properly.

    Do you have any suggestion?

    Thanks a lot, G
    Click image for larger version

Name:	Cattura.JPG
Views:	1
Size:	18.7 KB
ID:	1528521

  • #2
    Code:
    . di %9.2f  0.1
         0.10

    Comment


    • #3
      I guess you're showing a marker label. To get a display format consistently, use a string variable:

      Code:
      gen toshow = string(markervar, "%3.2f")

      Comment


      • #4
        Dear Andrew, Nick,

        thanks for your answers. The first solution (Andrew's one) apparently did not change anything to my graph, while regarding the Nick's one it changed the labels but not in the way I would have liked to: indeed, it appears "0.10" instead of ".1", while I would like to have ".10", is that possible?

        Thanks a lot, best, G

        Comment


        • #5
          Code:
          replace toshow = substr(toshow, 2, .) if substr(toshow, 1, 1) == "0"

          Comment


          • #6
            Dear Nick,

            thanks a lot, it works perfectly, I never realized that the command substr can be used to fix the labels.

            Very appreciated.

            Best, G

            Comment


            • #7
              The point is rather that marker labels can be string variables and that you can control the content of string variables. Those are independent facts which are unrelated, but you just need to use both ideas together.
              Last edited by Nick Cox; 16 Dec 2019, 06:50.

              Comment

              Working...
              X