Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #16632
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Specification error for Math.round |
| Date | 2012-10-14 11:09 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <k5e6h9$2cg$3@dont-email.me> (permalink) |
| References | <6dc8cb55-c29c-4bb2-ab6d-d9a9447cffd4@googlegroups.com> <b07ab1c9-fbf6-4c55-964e-17a69be1a7f3@googlegroups.com> <39e06fb5-7d74-4b5d-83bf-d2f7b3181168@googlegroups.com> |
On Thu, 11 Oct 2012 21:46:33 -0700, RobG wrote:
> On Friday, 12 October 2012 06:16:03 UTC+10, Danny wrote:
>> Math wise, usually x+0.5 should give x+1 as a rounded figure
>
> Not at all. If x is a decimal, then:
>
> 2.75 rounds to 3 2.75 + 0.5 = 3.25 which also rounds to 3
>
> If x is an integer, then for simple rounding you are correct.
I suspect that was the case that Danny was referring to.
Normally, for any "whole number" x.0, I would expect decimal fractions in
the range (x.0 - 0.5) .. (x.0 + 0.49999999999999999999999999..) to round
to x.
I think this is what you get if your rounding function f(x) is
{return Math.floor(x+0.5);}
I think (1) it's probably better to keep your numbers away from the cases
where errors may occur, and (2) if you want to process numbers with that
much precision, don't use javascript.
Rgds
Denis McMahon
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Specification error for Math.round RobG <rgqld@iinet.net.au> - 2012-10-10 19:52 -0700
Re: Specification error for Math.round Patricia Shanahan <pats@acm.org> - 2012-10-11 07:29 +0100
Re: Specification error for Math.round Dr J R Stockton <reply1241@merlyn.demon.co.uk.invalid> - 2012-10-12 23:00 +0100
Re: Specification error for Math.round Danny <dann90038@gmail.com> - 2012-10-11 13:16 -0700
Re: Specification error for Math.round Patricia Shanahan <pats@acm.org> - 2012-10-12 00:14 +0100
Re: Specification error for Math.round RobG <rgqld@iinet.net.au> - 2012-10-11 21:46 -0700
Re: Specification error for Math.round Patricia Shanahan <pats@acm.org> - 2012-10-12 08:28 +0100
Re: Specification error for Math.round Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-10-13 22:14 +0200
Re: Specification error for Math.round Patricia Shanahan <pats@acm.org> - 2012-10-13 21:45 +0100
Re: Specification error for Math.round "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-10-13 23:59 +0200
Re: Specification error for Math.round Dr J R Stockton <reply1241@merlyn.demon.co.uk.invalid> - 2012-10-13 19:31 +0100
Re: Specification error for Math.round Denis McMahon <denismfmcmahon@gmail.com> - 2012-10-14 11:09 +0000
Re: Specification error for Math.round Dr J R Stockton <reply1241@merlyn.demon.co.uk.invalid> - 2012-10-12 22:48 +0100
csiph-web