float print formatting

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • hg

    float print formatting

    Hi,

    Considering the float 0.0, I would like to print 00.00.

    I tried '%02.02f' % 0.0 ... but I get 0.00

    Any clue ?

    Thanks,

    hg

  • NOSPAM plz

    #2
    Re: Mulig SPAM: float print formatting

    hg skrev:
    Hi,
    >
    Considering the float 0.0, I would like to print 00.00.
    >
    I tried '%02.02f' % 0.0 ... but I get 0.00
    >
    Any clue ?
    >
    Thanks,
    >
    hg
    >
    >
    Try this:

    a = 45.45 # the floating number

    print "some text",
    print a,
    print "some text again"

    or just this:

    print "some text",
    print 45.45,
    print "some text again"

    Hope it helped :D

    Andreas


    Comment

    • Neil Cerutti

      #3
      Re: float print formatting

      On 2007-02-13, hg <hg@nospam.orgw rote:
      Hi,
      >
      Considering the float 0.0, I would like to print 00.00.
      >
      I tried '%02.02f' % 0.0 ... but I get 0.00
      >
      Any clue ?
      Yes. How wide (total) is "0.00", compared to "00.00"?

      --
      Neil Cerutti

      Comment

      • hg

        #4
        Re: float print formatting

        Neil Cerutti wrote:
        On 2007-02-13, hg <hg@nospam.orgw rote:
        >Hi,
        >>
        >Considering the float 0.0, I would like to print 00.00.
        >>
        >I tried '%02.02f' % 0.0 ... but I get 0.00
        >>
        >Any clue ?
        >
        Yes. How wide (total) is "0.00", compared to "00.00"?
        >
        --
        Neil Cerutti
        I do not get it


        s = '%02.02f' % 0.0
        s
        >'0.00'
        len(s)
        >4

        Comment

        • hg

          #5
          Re: Mulig SPAM: float print formatting

          NOSPAM plz wrote:
          hg skrev:
          >Hi,
          >>
          >Considering the float 0.0, I would like to print 00.00.
          >>
          >I tried '%02.02f' % 0.0 ... but I get 0.00
          >>
          >Any clue ?
          >>
          >Thanks,
          >>
          >hg
          >>
          >>
          Try this:
          >
          a = 45.45 # the floating number
          >
          print "some text",
          print a,
          print "some text again"
          >
          or just this:
          >
          print "some text",
          print 45.45,
          print "some text again"
          >
          Hope it helped :D
          >
          Andreas
          Sorry,

          must be very slow or not enough coffee yet ... my purpose is to display a
          justified report, so I format my floats into strings which I next draw in a
          bitmap.

          hg


          Comment

          • Peter Otten

            #6
            Re: float print formatting

            hg wrote:
            Considering the float 0.0, I would like to print 00.00.
            >
            I tried '%02.02f' % 0.0 ... but I get 0.00
            >
            Any clue ?
            The first integer specifies the total width:
            >>"%05.2f" % 0
            '00.00'

            Peter

            Comment

            • hg

              #7
              Re: float print formatting

              Peter Otten wrote:
              hg wrote:
              >
              >Considering the float 0.0, I would like to print 00.00.
              >>
              >I tried '%02.02f' % 0.0 ... but I get 0.00
              >>
              >Any clue ?
              >
              The first integer specifies the total width:
              >
              >>>"%05.2f" % 0
              '00.00'
              >
              Peter
              Many thanks !

              hg

              Comment

              • Neil Cerutti

                #8
                Re: float print formatting

                On 2007-02-13, hg <hg@nospam.orgw rote:
                Neil Cerutti wrote:
                >
                >On 2007-02-13, hg <hg@nospam.orgw rote:
                >>Hi,
                >>>
                >>Considering the float 0.0, I would like to print 00.00.
                >>>
                >>I tried '%02.02f' % 0.0 ... but I get 0.00
                >>>
                >>Any clue ?
                >>
                >Yes. How wide (total) is "0.00", compared to "00.00"?
                >>
                >--
                >Neil Cerutti
                >
                I do not get it
                >
                s = '%02.02f' % 0.0
                The first number after the percent is the minimum width specifier
                for the ENTIRE field.
                s
                >>'0.00'
                len(s)
                >>4
                It is the MINIMUM width specifier for the entire field.

                --
                Neil Cerutti
                The eighth-graders will be presenting Shakespeare's Hamlet in the church
                basement on Friday at 7 p.m. The congregation is invited to attend this
                tragedy. --Church Bulletin Blooper

                Comment

                • hg

                  #9
                  Re: float print formatting

                  Neil Cerutti wrote:
                  The eighth-graders will be presenting Shakespeare's Hamlet in the church
                  basement on Friday at 7 p.m. The congregation is invited to attend this
                  tragedy. --Church Bulletin Blooper
                  ;-) I like that !

                  hg

                  Comment

                  • Grant Edwards

                    #10
                    Re: float print formatting

                    On 2007-02-13, hg <hg@nospam.orgw rote:
                    Hi,
                    >
                    Considering the float 0.0, I would like to print 00.00.
                    >
                    I tried '%02.02f' % 0.0 ... but I get 0.00
                    ^^
                    That's the specifierfor how many total columns you want to use
                    (including the decimal point and all digits to either side).
                    Any clue ?
                    >>"%05.02f" % 0.0
                    '00.00'

                    --
                    Grant Edwards grante Yow! Yow!! "Janitor
                    at trapped in sewer uses ESP
                    visi.com to find decayed burger"!!

                    Comment

                    • Grant Edwards

                      #11
                      Re: Mulig SPAM: float print formatting

                      On 2007-02-13, hg <hg@nospam.orgw rote:
                      NOSPAM plz wrote:
                      >>Considering the float 0.0, I would like to print 00.00.
                      >>>
                      >>I tried '%02.02f' % 0.0 ... but I get 0.00
                      >Try this:
                      >>
                      >a = 45.45 # the floating number
                      >>
                      >print "some text",
                      >print a,
                      >print "some text again"
                      Sorry,
                      >
                      must be very slow or not enough coffee yet...
                      Don't worry. I do know what you did wrong and how to fix it,
                      and I have absolutely no idea what "NOSPAM plz" is trying to
                      say either.

                      --
                      Grant Edwards grante Yow! I'm in a twist
                      at contest!! I'm in a
                      visi.com bathtub! It's on Mars!! I'm
                      in tip-top condition!

                      Comment

                      • hg

                        #12
                        Re: float print formatting

                        Grant Edwards wrote:
                        On 2007-02-13, hg <hg@nospam.orgw rote:
                        >Hi,
                        >>
                        >Considering the float 0.0, I would like to print 00.00.
                        >>
                        >I tried '%02.02f' % 0.0 ... but I get 0.00
                        ^^
                        That's the specifierfor how many total columns you want to use
                        (including the decimal point and all digits to either side).
                        >
                        >Any clue ?
                        >
                        >>>"%05.02f" % 0.0
                        '00.00'
                        >
                        --
                        Grant Edwards grante Yow! Yow!! "Janitor
                        at trapped in sewer uses
                        ESP
                        visi.com to find decayed
                        burger"!!
                        Thanks

                        Comment

                        Working...