Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Round up the vaule

0 views
Skip to first unread message

Begineer

unread,
Oct 28, 2003, 10:49:22 PM10/28/03
to
Hello:

Would you mind to tell me how can I round up the value?

E.G. 1.9232052454 -> 1.92

Thanks!

--
Best Regards,
Alan Tang


Ray at <%=sLocation%>

unread,
Oct 28, 2003, 11:43:28 PM10/28/03
to
Disclaimer: I am no jscript expert by any means.

var x=Math.round(1.9232052454 * 100)/100;

Ray at home

"Begineer" <VOn...@ACO.RC> wrote in message news:3F9F38C2...@ACO.RC...

Roland Hall

unread,
Oct 29, 2003, 6:04:46 AM10/29/03
to
The response you got will round up to the 100ths position
if the 1000ths position is 5 or greater, otherwise it will
round off.

var x = Math.round(1.9232052454 * 100) / 100;
x = 1.92

var x = Math.round(1.9252052454 * 100) / 100;
x = 1.93

Microsoft says, "If the decimal portion of number is 0.5
or greater, the return value is equal to the smallest
integer greater than number. Otherwise, round returns the
largest integer less than or equal to number."

So...

[rounding to integer]
var x = Math.round(1.9252052454);
x = 2.0

[rounding to tenths]
var x = Math.round(1.9252052454 * 10) / 10;
x = 1.9

[rounding to hundredths]
var x = Math.round(1.9252052454 * 100) / 100;
x = 1.92

[rounding to thousandths]
var x = Math.round(1.9252052454 * 1000) / 1000;
x = 1.923

...and so on...

a working example...
http://kiddanger.com/lab/roundme.html

>.
>

Dr John Stockton

unread,
Oct 29, 2003, 10:49:59 AM10/29/03
to
JRS: In article <#9z1Bbdn...@TK2MSFTNGP10.phx.gbl>, seen in
news:microsoft.public.scripting.jscript, Ray at <%=sLocation%>
<myfir...@at.lane> posted at Tue, 28 Oct 2003 23:43:28 :-

>"Begineer" <VOn...@ACO.RC> wrote in message news:3F9F38C2...@ACO.RC...
>>
>> Would you mind to tell me how can I round up the value?
>>
>> E.G. 1.9232052454 -> 1.92

>Disclaimer: I am no jscript expert by any means.
>
>var x=Math.round(1.9232052454 * 100)/100;

Quoting rationalised and trimmed.

The OP is actually asking for that number to be rounded down.

The response gives a number with the nearest value which is a multiple
of 0.01, and is compatible with the question as asked, give/take
up/down.

However, a very common reason for asking such a question is that the
number is to be displayed with two decimal places - and that may mean
adding trailing zeroes - £1.00, £1.10, £1.11 etc. For that, it must at
some stage be converted to a string.

In an intranet, one may be able to use Number.toFixed(2) (but some
implementations of toFixed are said to be unreliable). However, toFixed
is not available in all browsers, so thought should be given before
using it on the Internet.


Code for rounding numbers in various ways can be found in the FAQ (sig
line 2) with more in <URL:http://www.merlyn.demon.co.uk/js-round.htm>.


The OP may also need to consider the difference between addition and
concatenation : FAQ, <URL:http://www.merlyn.demon.co.uk/js-maths.htm>.

--
© 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.

Dr John Stockton

unread,
Oct 29, 2003, 5:52:54 PM10/29/03
to
JRS: In article <0ace01c39e0c$76a9c6e0$a301...@phx.gbl>, seen in
news:microsoft.public.scripting.jscript, Roland Hall <anonymous@discussi
ons.microsoft.com> posted at Wed, 29 Oct 2003 03:04:46 :-

>The response you got will round up to the 100ths position
>if the 1000ths position is 5 or greater, otherwise it will
>round off.
>
>var x = Math.round(1.9232052454 * 100) / 100;
>x = 1.92
>
>var x = Math.round(1.9252052454 * 100) / 100;
>x = 1.93
>
>Microsoft says, "If the decimal portion of number is 0.5
>or greater, the return value is equal to the smallest
>integer greater than number. Otherwise, round returns the
>largest integer less than or equal to number."

You are conflating the issues of rounding a number to a number, with
binary representation, and rounding a string to a string, with decimal
representation, interspersed with that of converting a binary number to
a decimal string.

I trust that you are also using an E-mail address that falsely gives the
impression that you are associated with Microsoft; if it were otherwise,
it would explain too much.

Roland Hall

unread,
Oct 30, 2003, 8:46:25 AM10/30/03
to
John ole boy...

10, 100 and 1000 are integers, not binary
representations. I can see how you were confused. What
is that old saying? There are only 10 people in the
world, those that understand binary and those that don't.

Taken from here:
http://www.mozilla.org/js/language/js20-2000-
07/core/variables.html

"A variable defined with var can be modified, while one
defined with const is read-only. Identifier is the name of
the variable and TypeExpression is its type. Identifier
can be any non-reserved identifier. TypeExpression is
evaluated at the time the variable definition is evaluated
and should evaluate to a type t."

"If omitted, TypeExpression defaults to type any."

"Thus, the definition

var a, b=3, c:Integer=7, d, e:Type=Boolean, f:Number, g:e,
h:int;is equivalent to:

var a:any=undefined;
var b:any=3;
var c:Integer=7;
var d:Integer=undefined; // coerced to NaN
var e:Type=Boolean;
var f:Number=undefined; // coerced to NaN
var g:Boolean=undefined; // coerced to false
var h:int=undefined; // coerced to int(0)"

So, from what I gather you really have nothing to offer
other than what you think is wrong. You do not however
offer a solution of your own. Thus you give the
impression that you are a Liberal, no plan of your own,
just a complaint about someone else's plan.

The email address listed is what was the default when I
started to post, and M$ recommends not providing our
correct email address, due to spam, most likely from the
UK, thus I chose to leave the default. Once again, I
understand how YOU could be confused.

If all you have to offer is criticism and personal
attacks, perhaps you should seek counseling or a class on
anger management or go beat up your wife or kick your
dog. However, if you want to represent yourself as a
professional, then please offer suggestions that are worth
reading and provide your own solution(s) so we can all be
impressed.

useless dribble <snipped>

Dave Anderson

unread,
Oct 30, 2003, 4:22:45 PM10/30/03
to
"Roland Hall" wrote:
>
> 10, 100 and 1000 are integers, not binary
> representations...

Fully demonstrating that you missed his point. The original post asked how
to round a number to the nearest 100th, and most certainly was interested in
*displaying* his number with such a representation (why else would someone
be interested in losing precision?). This necessarily means representing the
number as a String.

There are two concepts you should familiarize yourself with:
1. n/100 cannot be exactly represented with a finite number of binary digits
for each integer n.
2. When exactly two decimals of output are desired, (n/100) is insufficient
if n%10 == 0. The subtype of Number.toFixed() is necessarily String.


> Taken from here:
> http://www.mozilla.org/js/language/js20-2000-07/core/variables.html

This is a JScript forum, not a JavaScript one. Nevertheless, we could defer
to ECMA-262 for reaching common ground...


> "A variable defined with var can be modified, while one
> defined with const is read-only.

ECMA-262, 7.5.3 defines [const] as a Future Reserved Word.


> Identifier is the name of the variable and TypeExpression
> is its type. Identifier can be any non-reserved identifier.
> TypeExpression is evaluated at the time the variable
> definition is evaluated and should evaluate to a type t."
>
> "If omitted, TypeExpression defaults to type any."

"TypeExpression" appears nowhere in ECMA-262.


> "Thus, the definition...[snip]

More like: "Thus, you have no meaningful argument in this forum"


> So, from what I gather you really have nothing to offer
> other than what you think is wrong.

You apparently do not gather much, then. John has a long and consistent
history of providing this group with useful insight into JScript issues,
especially with regard to numbers and dates. Spend 5 minutes on a Google
Groups search and you'll be well-armed to rebut yourself.


> The email address listed is what was the default when I
> started to post, and M$ recommends not providing our
> correct email address, due to spam, most likely from the
> UK, thus I chose to leave the default.

I eagarly await proof of such a Microsoft recommendation. You should note
that it looks foolish to act as though the Word Of Microsoft bears sway with
someone who uses M$ as a label.


> Once again, I understand how YOU could be confused.
>
> If all you have to offer is criticism and personal
> attacks, perhaps you should seek counseling or a class on
> anger management or go beat up your wife or kick your
> dog. However, if you want to represent yourself as a
> professional, then please offer suggestions that are worth
> reading and provide your own solution(s) so we can all be
> impressed.
>
> useless dribble <snipped>

Pot, kettle, plonk.


--
Dave Anderson, who uses spammotel rather than deceit to mask his real email
address

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.


Roland Hall

unread,
Oct 30, 2003, 6:21:11 PM10/30/03
to
Hi Dave...

Thanks for your response.

You're probably correct. I did miss his point because I
could not get past his rudeness. It's not John's
expertise I have a problem with, it was his delivery on
this thread.

>I eagarly await proof of such a Microsoft recommendation.

http://msdn.microsoft.com/newsgroups/

I would post the 5 paragraphs that are listed under the
heading "Reducing spam associated with posting to
newsgroups" but it is easy enough for you to browse there.

I'm not using an NNTP reader and as I stated earlier, the
address is offered when I post. It is not saved anywhere
on my system. Perhaps if you browse to the newsgroups and
post through your browser, you might obtain the same
results? Perhaps it's tied to a cookie, I don't know. I
don't care. I do not want any email so I chose the path
of least resistance. It offered, I accepted. And pot,
kettle, plonk on your tag.

MS in the states is Mississippi
M$ denotes Microsoft. Where did it come from? I first
saw it on a Linux site and M$ represented 'commercial -
private' vs 'open system.'

>You should note that it looks foolish to act as though
the Word Of Microsoft bears sway with someone who uses M$
as a label.

You should note that is your opinion and you have passed
judgment based on your knowledge without any facts.

I come to the Newsgroups to gain knowledge and help where
I can. I offer my suggestions and if someone finds fault
with it, they are welcome to offer their own solution.
Isn't that why we're here? Or is it just to criticize
those that you disagree with?

I can take corrective criticism and welcome it. What I do
not enjoy is people who try to alter my philosophy or
attack my person. You don't know me and if you were in my
presence, I doubt you would be so direct but then I don't
know you.

Someone posted "don't top post in usenet.", not to me but
to someone else. If the message is already posted, why
read through it again and have to scroll down a long
thread to read the response? Some many like it
interspersed and I'm sure some do not. So what?

The email address listed was offered and chose to keep it
to avoid more spam and possibly now hate mail from the
UK. If you or anyone has a problem with it, I don't
care. I don't work for Microsoft, I'm not a Microsoft
representative except that I am a Microsoft Partner but
that does not make me a representative. I also use the M$
acronym, which you don't like, when conversing with
Microsoft. They never complained. Bottom line is, it's
really none of your business and it has nothing at all to
do with rounding numbers.

BTW Dave, where is your solution to the original post?
Offering reading material or documentation is not a
solution, it's a lead. If my professors had all told
me, "The answer is in the book, go figure it out", I would
have dropped out of college.

The point of this thread was to help someone and it has
gotten completely off topic and is ridiculous as best not
to mention a complete waste of time.

If you don't like me, the email address posted, my
answers, my responses, or my presentation, I don't care.
I am here to learn and offer suggestions to those that ask
for help. If you have a better solution, then why not
spend your time on that rather than on correcting my
responses, worrying about the email address posted or the
acronyms I use.

Just for you, I modified the email address. Have a nice
day!

>.
>

Dr John Stockton

unread,
Oct 30, 2003, 4:01:33 PM10/30/03
to
JRS: In article <04e001c39eec$36516400$a001...@phx.gbl>, seen in

news:microsoft.public.scripting.jscript, Roland Hall <anonymous@discussi
ons.microsoft.com> posted at Thu, 30 Oct 2003 05:46:25 :-

[ Irrelevant technical material ignored ]

>So, from what I gather you really have nothing to offer
>other than what you think is wrong. You do not however
>offer a solution of your own.

Yes, I do offer a solution for the OP, in an earlier article in another
branch of the thread. Not only do I there cite the FAQ, but I cite my
site which is where the solution in the FAQ came from. You, however,
were not asking for a solution.


>The email address listed is what was the default when I
>started to post, and M$ recommends not providing our
>correct email address, due to spam, most likely from the
>UK, thus I chose to leave the default.

OK; it is reasonable to assume that Microsoft is of similar intelligence
to its customers. A pity, though.

Dave Anderson

unread,
Oct 31, 2003, 11:45:34 AM10/31/03
to
"Roland Hall" wrote:
>
>> I eagarly await proof of such a Microsoft recommendation.
> http://msdn.microsoft.com/newsgroups/
>
> I would post the 5 paragraphs that are listed under the
> heading "Reducing spam associated with posting to
> newsgroups" but it is easy enough for you to browse there.

Microsoft recommends 2 approaches: (1) a secondary email account, and (2)
modifying your actual email address so that human responders can extract it,
but automated systems mining USENET for addresses will get a bogus address.
You used <anon...@discussions.microsoft.com>, which clearly meets neither
of the "M$" recommendations. This "proof" fails the sniff test.


> I can take corrective criticism and welcome it. What I
> do not enjoy is people who try to alter my philosophy
> or attack my person. You don't know me and if you were
> in my presence, I doubt you would be so direct but
> then I don't know you.

Assume for a moment that you were unfairly criticized for attacking John,
and that it was unfair because the medium is resistent to nuance. We didn't
hear your tone, thus taking your constructive criticsm for rabid attack.
Turn that idea around and see if that applies to the things written about
your posts.

I wholeheartedly suggest you read the entire thread with an eye toward
personal attacks. See who mentions wife beating or who sinks to the "my unit
is bigger than yours" level (ex: "I can see how YOU could be confused").
Keep score. Let us know if we have been unfair.


> Someone posted "don't top post in usenet.", not to me
> but to someone else. If the message is already posted,
> why read through it again and have to scroll down a
> long thread to read the response? Some many like it
> interspersed and I'm sure some do not. So what?

I can tell you without looking that it wasn't me. I know this because I
personally think there are appropriate times to top-post in USENET. If a
response is to a post in its entirety, I prefer to see the post on top. If
it addresses a portion of a post, then I like to see a representative
snippet of the original post (with as much trimmed as is reasonable),
followed by an inline response. This type of response is typically
interlaced, as I have done in this message.


> The email address listed was offered and chose to
> keep it to avoid more spam and possibly now hate
> mail from the UK. If you or anyone has a problem
> with it, I don't care.

You say you can take constructive criticism. Here's some: You could have
ignored John's comment. Nobody would have followed it up. But you responded
in a way that invited further comment. And FWIW, I haven't got a clue to
explain why you keep mentioning spam from the UK. What does the UK have to
do with using a false address?


> I also use the M$ acronym, which you don't like...

I never expressed an opinion about it, BTW. I just said it looked foolish to
pair the use of "M$" with an "I obey Microsoft" protest. Note that I
expressed an opinion about neither thing. I just note that the contradiction
in subtext.


> BTW Dave, where is your solution to the original
> post? Offering reading material or documentation
> is not a solution, it's a lead. If my professors

> had all told me, "The anwer is in the book, go


> figure it out", I would have dropped out of
> college.

This is a common question, to which John had already offered a solution. My
contribution was to explain why John's solution was necessary (and by
implication why a solution not involving Strings was insufficient). Why
should I parrot what John said? Waste of bandwidth, as they say.


> The point of this thread was to help someone and it
> has gotten completely off topic and is ridiculous
> as best not to mention a complete waste of time.

Perhaps a glance at the thread could illustrate just where it went off the
rails. Were I you, I wouldn't be doing a lot of finger pointing. We hold
hypocrisy as a grievous sin.

--
Dave Anderson

Dr John Stockton

unread,
Oct 31, 2003, 1:52:01 PM10/31/03
to
JRS: In article <03ed01c39f3c$819add10$a401...@phx.gbl>, seen

in news:microsoft.public.scripting.jscript, Roland Hall
<nobody@nowhere.?> posted at Thu, 30 Oct 2003 15:21:11 :-

>You're probably correct. I did miss his point because I
>could not get past his rudeness.

The purpose, of course, was to indicate the situation to the
original poster, presumed to be still reading the thread.
Benefit to yourself would have been an unexpected bonus. Those
who cannot tolerate criticism should take care to give only
impeccable answers.


>MS in the states is Mississippi

The Internet extends beyond the United States; most users are
not in the US. MS for Mississippi should only be used on the
Net when the context implies that an American location is being
referred to. Internationally, of course, MS is the country code
for Montserrat (a much nicer place, apart from the volcano); it
should only be used for Microsoft in a software/bigbiz context.


>Someone posted "don't top post in usenet.", not to me but
>to someone else. If the message is already posted, why
>read through it again and have to scroll down a long
>thread to read the response? Some many like it
>interspersed and I'm sure some do not. So what?


A foolish remark to post, as it amounts to a recommendation of
its antithesis. Top-posting is almost invariably accompanied by
full-quoting, so its antithesis will also be. Full-quoting is a
waste of resources, for two reasons at least.

1) Bandwidth, storage. Some users are not using large machines
on fast cheap links.

2) It is much more effort for the readers to see which parts of
the earlier article are being replied to. That is important for
everyone, though more so for the physically disadvantaged.

"Put replies after trimmed quotes" is brief and to the point;
but it could possibly be improved upon.

Lee

unread,
Nov 1, 2003, 2:58:04 PM11/1/03
to
Dr John Stockton said:

>>MS in the states is Mississippi
>
>The Internet extends beyond the United States; most users are
>not in the US.

You're too eager to beat up Americans for making that sort
of mistake, and have jumped the gun. The poster was not
suggesting that anybody outside the US should be aware that
"MS" is the US Postal Service abbreviation for Mississippi.

He was simply explaining that, since it has this other
meaning "in the states", he had ruled it out as a way of
writing "Microsoft".

Roland Hall

unread,
Nov 1, 2003, 4:29:00 PM11/1/03
to
Lee...

You are beating a dead horse here. Dr. John and Dave have chosen to
disagree with my answer rather than offering any code to the user to help
them and even though I have touched on this several times, they still choose
to argue with me rather than offer a solution for the user. I appreciate
your understanding but you might soon be targeted.

Good luck to you.

Roland

"Lee" <REM0VElb...@cox.net> wrote in message
news:bo138...@drn.newsguy.com...

Lee

unread,
Nov 1, 2003, 4:17:53 PM11/1/03
to
Roland Hall said:
>
>Lee...
>
>You are beating a dead horse here. Dr. John and Dave have chosen to
>disagree with my answer rather than offering any code to the user to help
>them and even though I have touched on this several times, they still choose
>to argue with me rather than offer a solution for the user. I appreciate
>your understanding but you might soon be targeted.

Thanks, but I don't expect to be targeted for pointing
out a misunderstanding. Dr Stockton is rabidly anti-
American, but not completely irrational, otherwise.

By the way, he did point out the FAQ in his original post,
which should answer the original poster's question.

Dr John Stockton

unread,
Nov 2, 2003, 11:52:45 AM11/2/03
to
JRS: In article <bo138...@drn.newsguy.com>, seen in news:microsoft.p
ublic.scripting.jscript, Lee <REM0VElb...@cox.net> posted at Sat, 1
Nov 2003 11:58:04 :-


The Internet extends over hundreds of countries. Arguments based on an
alternative meaning, generally contextually distinguishable, in just one
of those countries are not appropriate on the Net. The company itself
has chosen to sell a product called MS-DOS - there is no reason to avoid
the use of MS for Microsoft in an international medium, except in those
rather rare contexts where Mississippi would make sense.

By the way, he suggested "due to spam, most likely from the UK,"; it
would be interesting to know whether anyone believes that he might have
a justification for writing that. ISTM that the general experience is
that a much larger proportion is manifestly US-linked or aimed mainly at
the US market - little, for example, acknowledges the Euro, which must
now be the most commonly-used currency outside China and India.

A better reason for avoiding the abbreviation is that it is used for a
distressing illness.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)

Lee

unread,
Nov 2, 2003, 5:01:25 PM11/2/03
to
Dr John Stockton said:
>
>The Internet extends over hundreds of countries. Arguments based on an
>alternative meaning, generally contextually distinguishable, in just one
>of those countries are not appropriate on the Net. The company itself
>has chosen to sell a product called MS-DOS - there is no reason to avoid
>the use of MS for Microsoft in an international medium, except in those
>rather rare contexts where Mississippi would make sense.

Again, he seemed to be explaining why he chose not to use the
abbreviation, himself. In his mind, it is confusing with
Mississippi. That's a good enough reason for him to want to
avoid using it.

I would guess that "M$" is recognized pretty widely, even
outside primarily English-speaking countries, wherever Bill
Gates has left his stamp.

>By the way, he suggested "due to spam, most likely from the UK,"; it
>would be interesting to know whether anyone believes that he might have
>a justification for writing that.

I would say that he's just Yanking your chain.

0 new messages