formatting

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

    formatting

    Hi,

    Is it possible to align numbers on the point of a float such as:

    15.223
    342.4457
    12.48





    instead of

    15.223
    342.4457
    12.4878

    thx,

    Alain



  • Frank Schummertz

    #2
    Re: formatting

    alain dhaene schrieb:

    [color=blue]
    > Is it possible to align numbers on the point of a float such as:
    >
    > 15.223
    > 342.4457
    > 12.48[/color]

    Easiest way would be to use http://php.net/sprintf for formatting the
    numbers.

    Frank

    --


    Comment

    • Markus Ernst

      #3
      Re: formatting

      "alain dhaene" <a.dhaene@instr uct.be> schrieb im Newsbeitrag
      news:407fa4c0$0 $429$a0ced6e1@n ews.skynet.be.. .[color=blue]
      > Hi,
      >
      > Is it possible to align numbers on the point of a float such as:
      >
      > 15.223
      > 342.4457
      > 12.48
      >
      > instead of
      >
      > 15.223
      > 342.4457
      > 12.4878[/color]

      As HTML does not know tabulators you will have to specify a monospaced font
      or put your output into <pre> </pre> tags. Then you have to figure out how
      many figures the highest and the actual numbers have before the decimal
      point, then you can add the difference in spaces.

      HTH
      Markus


      Comment

      • John Dunlop

        #4
        Re: formatting

        alain dhaene wrote:
        [color=blue]
        > Is it possible to align numbers on the point of a float such as:
        >
        > 15.223
        > 342.4457
        > 12.48[/color]

        For a webpage? Yes. There are a couple of options. Which is best
        depends on your situation, which you haven't described.

        Theoretically, if the data is columnar, you might use the char
        attribute in conjunction with align="char"; in practice, however,
        browser support probably isn't encouraging. In relation to
        align="char", the spec says "[i]f a user agent doesn't support
        character alignment, behavior in the presence of this value is
        unspecified". Moreover, it goes on to say that "[u]ser agents are not
        required to support [the char attribute]". See HTML4.01, sec. 11.3.2.

        More logically -- and perhaps even more theoretically! -- you'd use
        CSS2's text-align property with a value of ".". See CSS2, sec. 16.2.

        Another possibility is to right align the numbers and pad out with
        zeros -- padding with spaces won't work. ObPHP: sprintf has already
        been mentioned:



        The PRE element has been mentioned too. This marks the enclosed text
        as preformatted.

        --
        Jock

        Comment

        Working...