In comp.lang.javascript message <
[email protected]
However, it is often desirable to put a fixed number of characters
before the decimal point, as well as a fixed number of digits after it.
There's no way toFixed can do that, but the code cited, when not used to
emulate toFixed, has that option built in.
Many users directed to the FAQ would likely never work out how to use
the code provided, much less discover that the functions can be used
for other purposes. The names of the functions don't help - StrS is
hardly descriptive for a function that formats numbers.
It's a good idea to read the newsgroup c.l.j and its FAQ.
I have no idea whay you include that comment - did I miss something?
There is nothing in FAQ 4.6 that helps people use the code provided.
Your site provides a vast amount of information but doesn't provide
suitable FAQ-type help. If the FAQ was well worded, there'd be no need
for you to point out that the set of functions in 4.6 can be used for
other purposes.
For example:
function Stretch(Q, L, c) { var S = Q
if (c.length>0) while (S.length<L) { S = c+S }
return S
}
assumes Q and c are strings. To make it a more understandable and a
generic padding function, consider:
function padString( value, newLength, paddingChar)
{
var s = String(value);
var c = String(paddingChar);
if (c.length > 0) {
while (s.length < newLength) {
s = c + s;
}
}
return s;
}
alert( padString('abc', 6, '_')); // Shows ___abc
alert( padString(7, 3, '0')); // Shows 007
I'll offer a suggestion next time that entry is the FAQ post of the
day, it probably deserves its own notes page.