round

Yes. Many people, some for different reasons.

In the "What's the standard approach?" sense, however, the general
"standard" for numbers that either include endlessly repeating decimal
patterns (e.g. forever-repeating nines, as presumably in this case) or
limited decimal places, choose as necessary:

1. Go to the last digit after the precision you want for rounding that
does not round up the preceding digit. Perform rounding starting from
there, and stop when you've crawled back toward the whole number place
until you reach the precision level you want. This example involves
rounding to the first decimal fraction position, performing operations
one at a time:

    1.444445
    1.44445
    1.4445
    1.445
    1.45
    1.5

2. If the infinite repeating pattern is all numerals of <=5, round up
the last numeral before the first digit of the repeating pattern so you
don't have to endlessly recurse. This example is probably the example
under consideration in this email thread, assuming it's not simply the
number 1.449999 and is, in fact, 1.44 followed by a repetend of 9:

···

On Fri, Jun 19, 2020 at 11:55:16AM +0200, Christer Jansson wrote:

I would say 1.4 is the mathematically correct rounding, since 1.449999 <
1.45. Anyone disagree with that?

        __
    1.4499 # For those unaware, the bar signifies repeating 9s.
    1.44a # . . . where (a = <=5) for rounding purposes.
    1.45
    1.5

It's possible schools have simplified it to help people pass
standardized tests, though. Governments like to show the world they're
producing educated people, so practices that improve the scores people
tend to get may become "normal" in government funded schools and, as
such, ignoring most of the complexity of the long-term common rounding
approach can make it much easier for young students to pass tests by
allowing them to ignore any more than the number of digits needed for
their target fractional precision plus one reference digit for rounding.

There are many ways to round numbers, though, depending on the specific
needs of any given use case, so the "right" answer varies wildly from
case to case.

That, at least, is how I learned it years ago, across several different
school systems and levels of education, and in some math reading on my
own time for my own satisfaction.

--
Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]

Ignore my preceding message. I didn't notice it was a long-dead thread,
and didn't mean to re-open it. Sorry about that.

···

--
Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]

1.449999 is a stupid number to be discussing in IEEE 754 floating point
notation because, as a pure binary number, it does have a repeating pattern
of digits, but as a Float it's encoded as 0x28b9c3263233f73f which is most
definitely finite. And then you're rounding a number stored in truncated
binary according to its decimal representation. So you have to delve into
the specification of IEEE 754.

Or, like a sane person, treat it how it looks: a finite decimal number. In
which case, always round to precision by only considering the digit to the
right.

1.449999.round = 1
1.449999.round(1) = 1.4
1.449999.round(2) = 1.45
1.449999.round(3) = 1.45
etc.

The _only_ question, then, is if the relevant digit is exactly half way
(i.e. 5) and you have to chooses between round-to-even, round-towards-zero,
round-towards-positive-infinity, etc.

Cheers
Matthew Kerwin

···

On Thu., 17 Sep. 2020, 14:16 Chad Perrin, <code@apotheon.net> wrote:

This example is probably the example
under consideration in this email thread, assuming it's not simply the
number 1.449999 and is, in fact, 1.44 followed by a repetend of 9:

> I would say 1.4 is the mathematically correct rounding, since 1.449999 <
> 1.45. Anyone disagree with that?

Yes. Many people, some for different reasons.

In the "What's the standard approach?" sense, however, the general
"standard" for numbers that either include endlessly repeating decimal
patterns (e.g. forever-repeating nines, as presumably in this case)

Albeit, floating point numbers cannot represent those real numbers. For
that you need some form of symbolic mathematical system.

or
limited decimal places, choose as necessary:

1. Go to the last digit after the precision you want for rounding that
does not round up the preceding digit. Perform rounding starting from
there, and stop when you've crawled back toward the whole number place
until you reach the precision level you want. This example involves
rounding to the first decimal fraction position, performing operations
one at a time:

    1.444445
    1.44445
    1.4445
    1.445
    1.45
    1.5

If you want to round to one decimal place the result must be 1.4 and not
1.5. Regardless how many 4s you have in 1.444...5 the value 1.4 is always
closer to the original than 1.5. And proximity is one typical criterium for
rounding. According to what mathematical standard do you calculate your
values?

2. If the infinite repeating pattern is all numerals of <=5, round up
the last numeral before the first digit of the repeating pattern so you
don't have to endlessly recurse. This example is probably the example
under consideration in this email thread,

I do not see an endless pattern mentioned and also floats cannot represent
that.

assuming it's not simply the
number 1.449999 and is, in fact, 1.44 followed by a repetend of 9:

        __
    1.4499 # For those unaware, the bar signifies repeating 9s.
    1.44a # . . . where (a = <=5) for rounding purposes.
    1.45
    1.5

Rounding to 1 decimal gives 1.4, rounding to two 1.45 rounding to more
gives 1.450...0 - regardless whether there are indefinite many 9s or not.

It's possible schools have simplified it to help people pass
standardized tests, though. Governments like to show the world they're
producing educated people, so practices that improve the scores people
tend to get may become "normal" in government funded schools and, as
such, ignoring most of the complexity of the long-term common rounding
approach can make it much easier for young students to pass tests by
allowing them to ignore any more than the number of digits needed for
their target fractional precision plus one reference digit for rounding.

I am not sure I am buying that. Sure, there are many approaches to rounding
that schools do not cover, but I do not see the rounding algorithm that you
describe as a standard somewhere. Is it on the Wikipedia page?

There are many ways to round numbers, though, depending on the specific
needs of any given use case, so the "right" answer varies wildly from
case to case.

Agree, the Wikipedia page documents that.

Generally I believe it is a bad idea to roll your own rounding algorithm -
especially if you want to continue calculations with rounded values. Then a
lot of thought has to go in that and you potentially also lose the IEEE
support in hardware. Also, people might misinterpret rounded numbers if
there is an unobvious algorithm used that is not the standard.

Usually it is best to only round on output for humans and not internally so
calculations can proceed with the best precision.

Cheers

robert

···

On Thu, Sep 17, 2020 at 6:14 AM Chad Perrin <code@apotheon.net> wrote:

On Fri, Jun 19, 2020 at 11:55:16AM +0200, Christer Jansson wrote:

--
[guy, jim, charlie, sho].each {|him| remember.him do |as, often| as.you_can
- without end}
http://blog.rubybestpractices.com/