Steve van Dongen Wrote:
nov (AT) eastontario (DOT) com (Gord) wrote:
exactly the same as only appending temp to "0".
Posting things like this are next to useless IMO. It's one thing to
post a library or a complex function, but what's the point behind such
a simple function of highly specific purpose that can be written
better in 2 lines?
function zeroUpFront(n)
{
n = "00" + n;
return n.substring(n.length-2);
}
BTW, your function doesn't do what you says it does. For inputs 11
through 99 it returns a number, not a string.
Regards,
Steve
You're partially right, returned is a number if not a single digit.
I think your function is quite different from mine, though recently it
occurred to me that "terser" would have been
function zeroUpFront(nDigits){
temp = nDigits
temp = temp>=100? temp%100:temp
temp = temp<10? ("0" + temp): ("" + temp)
return temp;
}
as used in:
http://eastontario.com/handStories/entry.htm
If you click on one the linked "Deal" links on that page, you'll end up
on another page perhaps of interest, more complex a creation than the
little function above.
I was once very impressed with the simple function suggested on a group
incorporated in the page at:
http://eastontario.com/handStories/handTEMPLATE.htm
which is
var url =
location.href.substring(location.href.length-52,location.href.length);
location.href
is basically it, perhaps an identity more than a function, or a method
Sometimes to just add one more function in to all the rest causes a
chain reaction.
It seemed that the zeroUpFront function was one that perhaps was long
overdue posting, even if so simple.
It wasn't a brainchild, but it seemed it would have been helpful to
have seen it posted somewhere long ago, underlining also the deviance
of javascript from necessary 'casting'.
:cool:
--
eastontario
------------------------------------------------------------------------
eastontario's Profile:
http://www.highdots.com/forums/m216
View this thread:
http://www.highdots.com/forums/t28612