Dr
Mon Sep 01 11:33:14 CDT 2003
JRS: In article <Od#4InybDHA.2580@TK2MSFTNGP12.phx.gbl>, seen in
news:microsoft.public.scripting.vbscript, Diana Castillo <diana.castillo
@nvtechnologies.com> posted at Sat, 30 Aug 2003 21:04:11 :-
>
>The round function in asp doesnt round a number ending in five up. I need to
>round to two digits round(num, 2) but I need it to round up when the last
>digit is five, does anyone have a function for doing that ?
This is a VBScript newsgroup.
I've only seen the combination of asp & javascript before.
One wonders exactly what you mean by "a number ending in five". A
number may be represented as a string, or as a binary integer, or in
floating-point, usually binary.
Only when in string form can it really be said to end in 5.
If you need to round such as 12.345, then it cannot be an integer. It
can be a string, in which case it is best to detect the 5 using string
operations. If it is a number, then it cannot (in likely circumstances)
be exact, since 0.345 is not a multiple of 2^-n for n <= likely mantissa
length. Therefore, a proper mathematical rounding may either round it
up or down.
See <URL:
http://www.merlyn.demon.co.uk/js-round.htm> for rounding in
javascript; see also <URL:
http://www.merlyn.demon.co.uk/pas-chop.htm>.
Beware of javascript "solutions" that work only with specific browsers.
Note that rounding to two digits implies string output, and that 0.00,
1.00, 1.30 are possible results. It is not the same as rounding to a
multiple of 0.01 or of 1/100 with a result of numeric type.
Variations of the following give interesting results with Evertjan's
second function in my browser.
for (J=12290 ; J<=12410 ; J+=5) {
Q = J*0.001 // or J/1000
document.write(J, ' ', Q, ' ', round(Q, 2), '<br>')
}
Note that J*0.001 is not always equal to J/1000.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:
http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:
http://www.merlyn.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:
http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.