Re: how to use a static variable?
- From: Dr John Stockton <jrs@xxxxxxxxxxxxxxxxxx>
- Date: Sat, 23 Jul 2005 17:06:45 +0100
JRS: In article <OtX#ZIsjFHA.476@xxxxxxxxxxxxxxxxxxxx>, dated Fri, 22
Jul 2005 15:29:18, seen in news:microsoft.public.scripting.jscript,
Chris <rrr@xxxx> posted :
>tempsreel= new Date()
>trh=tempsreel.getHours()
>trm=tempsreel.getMinutes()
>trs=tempsreel.getSeconds()
>te=parseInt(trh)*3600+parseInt(trm)*60+parseInt(trs)
Other things apart, those parseInt calls are worse than useless.
Variables trh trm trs are set, by those .get calls, to Numbers. The
arguments are then converted to strings for parseInt, which converts
them back. Use
te = (trh*60+trm)*60+trs ;
When use of parseInt is actually justified, then one should consider
whether it needs a second parameter; it will do so if there is any risk
of leading zeroes in the strings provided. Unless in the string there
are other characters following the number part, ISTM better to use a
unary + for string-to-integer conversion : I = + S ; .
See sig below.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
.
- Follow-Ups:
- Re: how to use a static variable?
- From: Chris
- Re: how to use a static variable?
- References:
- how to use a static variable?
- From: Chris
- how to use a static variable?
- Prev by Date: Re: hiding rows in a table
- Next by Date: Re: How to convert International number strings to their number values
- Previous by thread: Re: how to use a static variable?
- Next by thread: Re: how to use a static variable?
- Index(es):
Relevant Pages
|