By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,642 Members | 1,672 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,642 IT Pros & Developers. It's quick & easy.

formatting

P: n/a
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

Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
alain dhaene schrieb:

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

15.223
342.4457
12.48


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

Frank

--
http://www.pncommerce.com
http://www.landseer-stuttgart.de
Jul 17 '05 #2

P: n/a
"alain dhaene" <a.******@instruct.be> schrieb im Newsbeitrag
news:40*********************@news.skynet.be...
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


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
Jul 17 '05 #3

P: n/a
alain dhaene wrote:
Is it possible to align numbers on the point of a float such as:

15.223
342.4457
12.48


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:

http://www.php.net/manual/en/function.sprintf.php

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

--
Jock
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.