# round

**URL:** <https://rubytalk.org/t/round/75273>\
**Category:** ruby-talk\
**Created:** [19 June 2020 09:08 UTC](https://rubytalk.org/t/round/75273 "2020-06-19T09:08:34Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Die\_Optimisten](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@Die\_Optimisten](https://rubytalk.org/u/Die_Optimisten)\
**Post date:** [19 June 2020 09:08 UTC](https://rubytalk.org/t/round/75273/1 "2020-06-19T09:08:34Z")

</div>

Hi,

1.449999.round(1) # 1.4 instead 4.5 ! (would be mathematical correct)

it seems only the next [one] digit after the relevant position is used  
for calculation.

Nobody wondering of this? Isn't that a problem in many use cases?

It can't be a bit-precision problem, because that would affect much  
lower digits.

Looking into the doku: ... aha - additional features:  
for me half: in my opinion up/down is misleading - up is always in the  
direction of the greater number (mathematical +, also see .upto),

even seems to round to the nearest even number. Why is there is no odd  
(I would assume in all use cases odd is needed the same as even, besides  
that nobody would need any of them, or? 🙂

Andrew

---

<div class="post-metadata">

**Author:** ![Lee\_Hambley](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/lee_hambley/32/2179_2.png) [@Lee\_Hambley](https://rubytalk.org/u/Lee_Hambley)\
**Post date:** [19 June 2020 09:17 UTC](https://rubytalk.org/t/round/75273/2 "2020-06-19T09:17:50Z")

</div>

I guess it's an artifact of IEEE754? I tried this in Rust (let's say I  
expect Rust to be a better reference than maybe Ruby's organically grown  
library)

Try [https://play.rust-lang.org/](https://play.rust-lang.org/)

fn main() {  
&nbsp;&nbsp;&nbsp;&nbsp;println!("{:.1}", 1.449999);  
}

It outputs 1.4 too. I also explored  
[IEEE-754 Floating Point Converter](https://www.h-schmidt.net/FloatConverter/IEEE754.html) and made a  
best-effort to understand  
[IEEE 754 - Wikipedia](https://en.wikipedia.org/wiki/IEEE_754#Rounding_rules)

Lee Hambley

> **[Notion – The all-in-one workspace for your notes, tasks, wikis, and databases.](https://sphenoid-raptor-ca0.notion.site/lee-hambley-name-8c4d10c91f8e47588eae043b6e9a66ac)**
>
> A new tool that blends your everyday work apps into one. It's the all-in-one workspace for you and your team

+49 (0) 170 298 5667

> **···**
>
> On Fri, 19 Jun 2020 at 11:09, Die Optimisten \<inform@die-optimisten.net\> wrote:
> 
> > Hi,
> > 
> > 1.449999.round(1) # 1.4 instead 4.5 ! (would be mathematical correct)
> > 
> > it seems only the next [one] digit after the relevant position is used  
> > for calculation.
> > 
> > Nobody wondering of this? Isn't that a problem in many use cases?
> > 
> > It can't be a bit-precision problem, because that would affect much  
> > lower digits.
> > 
> > Looking into the doku: ... aha - additional features:  
> > for me half: in my opinion up/down is misleading - up is always in the  
> > direction of the greater number (mathematical +, also see .upto),
> > 
> > even seems to round to the nearest even number. Why is there is no odd  
> > (I would assume in all use cases odd is needed the same as even, besides  
> > that nobody would need any of them, or? 🙂
> > 
> > Andrew
> > 
> > Unsubscribe: \<mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe\>  
> > \<[http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);

---

<div class="post-metadata">

**Author:** ![Christer\_Jansson](https://avatars.discourse-cdn.com/v4/letter/c/cab0a1/32.png) [@Christer\_Jansson](https://rubytalk.org/u/Christer_Jansson)\
**Post date:** [19 June 2020 09:55 UTC](https://rubytalk.org/t/round/75273/3 "2020-06-19T09:55:16Z")

</div>

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

Christer Jansson

> **···**
>
> Den fre 19 juni 2020 kl 11:18 skrev Lee Hambley \<lee.hambley@gmail.com\>:
> 
> > I guess it's an artifact of IEEE754? I tried this in Rust (let's say I  
> > expect Rust to be a better reference than maybe Ruby's organically grown  
> > library)
> > 
> > Try [https://play.rust-lang.org/](https://play.rust-lang.org/)
> > 
> > fn main() {  
> > &nbsp;&nbsp;&nbsp;&nbsp;println!("{:.1}", 1.449999);  
> > }
> > 
> > It outputs 1.4 too. I also explored  
> > [IEEE-754 Floating Point Converter](https://www.h-schmidt.net/FloatConverter/IEEE754.html) and made a  
> > best-effort to understand  
> > [IEEE 754 - Wikipedia](https://en.wikipedia.org/wiki/IEEE_754#Rounding_rules)
> > 
> > Lee Hambley  
> > [http://lee.hambley.name/](http://lee.hambley.name/)  
> > +49 (0) 170 298 5667
> > 
> > On Fri, 19 Jun 2020 at 11:09, Die Optimisten \<inform@die-optimisten.net\> \> wrote:
> > 
> > > Hi,
> > > 
> > > 1.449999.round(1) # 1.4 instead 4.5 ! (would be mathematical correct)
> > > 
> > > it seems only the next [one] digit after the relevant position is used  
> > > for calculation.
> > > 
> > > Nobody wondering of this? Isn't that a problem in many use cases?
> > > 
> > > It can't be a bit-precision problem, because that would affect much  
> > > lower digits.
> > > 
> > > Looking into the doku: ... aha - additional features:  
> > > for me half: in my opinion up/down is misleading - up is always in the  
> > > direction of the greater number (mathematical +, also see .upto),
> > > 
> > > even seems to round to the nearest even number. Why is there is no odd  
> > > (I would assume in all use cases odd is needed the same as even, besides  
> > > that nobody would need any of them, or? 🙂
> > > 
> > > Andrew
> > > 
> > > Unsubscribe: \<mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe\>  
> > > \<[http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);
> > 
> > Unsubscribe: \<mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe\>  
> > \<[http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);

---

<div class="post-metadata">

**Author:** ![Tom\_Lord](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/tom_lord/32/2215_2.png) [@Tom\_Lord](https://rubytalk.org/u/Tom_Lord)\
**Post date:** [19 June 2020 10:15 UTC](https://rubytalk.org/t/round/75273/4 "2020-06-19T10:15:35Z")

</div>

Yes, I’m not sure where the confusion is…

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

If you round to one decimal place, then you can’t expect a result with two decimal places.

> **···**
>
> > On 19 Jun 2020, at 10:55, Christer Jansson \<datakonsult@janssons.org\> wrote:
> > 
> > I would say 1.4 is the mathematically correct rounding, since 1.449999 \< 1.45. Anyone disagree with that?
> > 
> > Christer Jansson
> > 
> > Den fre 19 juni 2020 kl 11:18 skrev Lee Hambley \<lee.hambley@gmail.com \<mailto:lee.hambley@gmail.com\>\>:  
> > I guess it's an artifact of IEEE754? I tried this in Rust (let's say I expect Rust to be a better reference than maybe Ruby's organically grown library)
> > 
> > Try [https://play.rust-lang.org/](https://play.rust-lang.org/)
> > 
> > fn main() {  
> > &nbsp;&nbsp;&nbsp;&nbsp;println!("{:.1}", 1.449999);  
> > }
> > 
> > It outputs 1.4 too. I also explored [IEEE-754 Floating Point Converter](https://www.h-schmidt.net/FloatConverter/IEEE754.html) and made a best-effort to understand [IEEE 754 - Wikipedia](https://en.wikipedia.org/wiki/IEEE_754#Rounding_rules)
> > 
> > Lee Hambley  
> > [http://lee.hambley.name/](http://lee.hambley.name/)  
> > +49 (0) 170 298 5667
> > 
> > On Fri, 19 Jun 2020 at 11:09, Die Optimisten \<inform@die-optimisten.net \<mailto:inform@die-optimisten.net\>\> wrote:  
> > Hi,
> > 
> > 1.449999.round(1) # 1.4 instead 4.5 ! (would be mathematical correct)
> > 
> > it seems only the next [one] digit after the relevant position is used  
> > for calculation.
> > 
> > Nobody wondering of this? Isn't that a problem in many use cases?
> > 
> > It can't be a bit-precision problem, because that would affect much  
> > lower digits.
> > 
> > Looking into the doku: ... aha - additional features:  
> > for me half: in my opinion up/down is misleading - up is always in the  
> > direction of the greater number (mathematical +, also see .upto),
> > 
> > even seems to round to the nearest even number. Why is there is no odd  
> > (I would assume in all use cases odd is needed the same as even, besides  
> > that nobody would need any of them, or? 🙂
> > 
> > Andrew
> > 
> > Unsubscribe: \<mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe\>  
> > \<[http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);
> > 
> > Unsubscribe: \<mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe\>  
> > \<[http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);
> > 
> > Unsubscribe: \<mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe\>  
> > \<[http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);

---

<div class="post-metadata">

**Author:** ![Xavier\_Noria](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/xavier_noria/32/1867_2.png) [@Xavier\_Noria](https://rubytalk.org/u/Xavier_Noria)\
**Post date:** [19 June 2020 10:31 UTC](https://rubytalk.org/t/round/75273/5 "2020-06-19T10:31:42Z")

</div>

This is how you round to 1 decimal using pencil and paper.

---

<div class="post-metadata">

**Author:** ![Die\_Optimisten](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@Die\_Optimisten](https://rubytalk.org/u/Die_Optimisten)\
**Post date:** [19 June 2020 19:15 UTC](https://rubytalk.org/t/round/75273/6 "2020-06-19T19:15:39Z")

</div>

Any math-people here, what is correct?

I would say using pencil and paper 1.4499.round(1)=1.5, because you have  
to begin with the LSB,  
so 1.44999 -\> 1.45 -\> 1.5. I'll ask my friend, what his kids are  
learning in school.  
(The other question is, if you can trust, that what people are told in  
school, is always correct... Buts thats another thread....)

What about the half-options? Seems hard to find anybody who has used /  
knows that feature? ;))

Andrew

---

<div class="post-metadata">

**Author:** ![Marc\_Chanliau](https://avatars.discourse-cdn.com/v4/letter/m/57b2e6/32.png) [@Marc\_Chanliau](https://rubytalk.org/u/Marc_Chanliau)\
**Post date:** [19 June 2020 19:38 UTC](https://rubytalk.org/t/round/75273/7 "2020-06-19T19:38:44Z")

</div>

2.7.1 :001 \> 1.4567.round(3)  
=\> 1.457  
2.7.1 :002 \> 1.563.round(2)  
=\> 1.56  
2.7.1 :003 \> 1.563.round  
=\> 2

> **···**
>
> > On Jun 19, 2020, at 12:15 PM, Die Optimisten \<inform@die-optimisten.net\> wrote:
> > 
> > Any math-people here, what is correct?
> > 
> > I would say using pencil and paper 1.4499.round(1)=1.5, because you have  
> > to begin with the LSB,  
> > so 1.44999 -\> 1.45 -\> 1.5. I'll ask my friend, what his kids are  
> > learning in school.  
> > (The other question is, if you can trust, that what people are told in  
> > school, is always correct... Buts thats another thread....)
> > 
> > What about the half-options? Seems hard to find anybody who has used /  
> > knows that feature? ;))
> > 
> > Andrew
> > 
> > Unsubscribe: \<mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe\>  
> > \<[http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);

---

<div class="post-metadata">

**Author:** ![Hassan\_Schroeder](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/hassan_schroeder/32/1838_2.png) [@Hassan\_Schroeder](https://rubytalk.org/u/Hassan_Schroeder)\
**Post date:** [19 June 2020 19:51 UTC](https://rubytalk.org/t/round/75273/8 "2020-06-19T19:51:34Z")

</div>

There is no one "correct" answer.

The "correct" answer is what's returned using the ROUNDING\_MODE  
that's appropriate to your use case (which may involve business rules  
and legal restrictions).

See for instance:

> **[Class: BigDecimal (Ruby 2.5.7)](https://ruby-doc.org/stdlib-2.5.7/libdoc/bigdecimal/rdoc/BigDecimal.html#method-c-mode)**
>
> Class : BigDecimal - Ruby 2.5.7

> **···**
>
> On Fri, Jun 19, 2020 at 12:16 PM Die Optimisten \<inform@die-optimisten.net\> wrote:
> 
> > Any math-people here, what is correct?
> 
> --  
> Hassan Schroeder ------------------------ hassan.schroeder@gmail.com  
> twitter: @hassan  
> Consulting Availability : Silicon Valley or remote

---

<div class="post-metadata">

**Author:** ![Juan\_DCG](https://avatars.discourse-cdn.com/v4/letter/j/e19adc/32.png) [@Juan\_DCG](https://rubytalk.org/u/Juan_DCG)\
**Post date:** [19 June 2020 20:00 UTC](https://rubytalk.org/t/round/75273/9 "2020-06-19T20:00:12Z")

</div>

Hi,

I'm not a professional mathematical, but when I was a child I remember that  
the rule applied when round 5 is:

If x \<= 5 then round to the minor  
If x \> 5 then round to the high

Then is this example it must be ( following this school rule ):

1,44999 -\> round(2)= 1,45  
1,45 -\> round(1)=\* 1,4\*  
1,4 -\< round= 1

That is the rule I remember.

But now, testing:

gems :001 \> 1.44999.round(3)  
=\> 1.45  
gems :002 \> 1.45.round(1)  
=\> 1.5  
gems :003 \> 1.5.round  
=\> 2  
gems :004 \> 1.44999.round  
=\> 1  
gems :005 \> 0.5.round  
=\> 1

I'm confused where search the official reference to round number, ¿some  
standard in mathematics ;)?  
because irb doesn't round like a school child ( in my school ), although  
when round complete number "my" rule is applied.

Regards,

> **···**
>
> El vie., 19 jun. 2020 a las 21:16, Die Optimisten (\< inform@die-optimisten.net\>) escribió:
> 
> > Any math-people here, what is correct?
> > 
> > I would say using pencil and paper 1.4499.round(1)=1.5, because you have  
> > to begin with the LSB,  
> > so 1.44999 -\> 1.45 -\> 1.5. I'll ask my friend, what his kids are  
> > learning in school.  
> > (The other question is, if you can trust, that what people are told in  
> > school, is always correct... Buts thats another thread....)
> > 
> > What about the half-options? Seems hard to find anybody who has used /  
> > knows that feature? ;))
> > 
> > Andrew
> > 
> > Unsubscribe: \<mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe\>  
> > \<[http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);

---

<div class="post-metadata">

**Author:** ![Martin\_DeMello](https://avatars.discourse-cdn.com/v4/letter/m/f17d59/32.png) [@Martin\_DeMello](https://rubytalk.org/u/Martin_DeMello)\
**Post date:** [19 June 2020 20:31 UTC](https://rubytalk.org/t/round/75273/10 "2020-06-19T20:31:36Z")

</div>

This page has a good overview of the issues around rounding; in particular  
check out the sections starting from "but being consistent can be bad"

[https://www.mathsisfun.com/numbers/rounding-methods.html](https://www.mathsisfun.com/numbers/rounding-methods.html)

martin

> **···**
>
> On Fri, Jun 19, 2020 at 1:00 PM Juan DCG \<juandcg314@gmail.com\> wrote:
> 
> > Hi,
> > 
> > I'm not a professional mathematical, but when I was a child I remember  
> > that the rule applied when round 5 is:
> > 
> > If x \<= 5 then round to the minor  
> > If x \> 5 then round to the high
> > 
> > Then is this example it must be ( following this school rule ):
> > 
> > 1,44999 -\> round(2)= 1,45  
> > 1,45 -\> round(1)=\* 1,4\*  
> > 1,4 -\< round= 1
> > 
> > That is the rule I remember.
> > 
> > But now, testing:
> > 
> > gems :001 \> 1.44999.round(3)  
> > =\> 1.45  
> > gems :002 \> 1.45.round(1)  
> > =\> 1.5  
> > gems :003 \> 1.5.round  
> > =\> 2  
> > gems :004 \> 1.44999.round  
> > =\> 1  
> > gems :005 \> 0.5.round  
> > =\> 1
> > 
> > I'm confused where search the official reference to round number, ¿some  
> > standard in mathematics ;)?  
> > because irb doesn't round like a school child ( in my school ), although  
> > when round complete number "my" rule is applied.
> > 
> > Regards,
> > 
> > El vie., 19 jun. 2020 a las 21:16, Die Optimisten (\< \> inform@die-optimisten.net\>) escribió:
> > 
> > > Any math-people here, what is correct?
> > > 
> > > I would say using pencil and paper 1.4499.round(1)=1.5, because you have  
> > > to begin with the LSB,  
> > > so 1.44999 -\> 1.45 -\> 1.5. I'll ask my friend, what his kids are  
> > > learning in school.  
> > > (The other question is, if you can trust, that what people are told in  
> > > school, is always correct... Buts thats another thread....)
> > > 
> > > What about the half-options? Seems hard to find anybody who has used /  
> > > knows that feature? ;))
> > > 
> > > Andrew
> > > 
> > > Unsubscribe: \<mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe\>  
> > > \<[http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);
> > 
> > Unsubscribe: \<mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe\>  
> > \<[http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);

---

<div class="post-metadata">

**Author:** ![Rob\_Biedenharn](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/rob_biedenharn/32/1859_2.png) [@Rob\_Biedenharn](https://rubytalk.org/u/Rob_Biedenharn)\
**Post date:** [19 June 2020 21:17 UTC](https://rubytalk.org/t/round/75273/11 "2020-06-19T21:17:52Z")

</div>

That section on Banker’s Rounding "Round to Even" should have repeated the example:

Before rounding: 5.5 + 7.5 + 6.5 + 9.5 = 29

After rounding: 6 + 8 + 6 + 10 = 30

To show that it’s "closer" to the real answer of 29. Assuming you had many more values, rounding to even attempt to "average out" the ups and downs of rounding x.50 to a whole amount.

-Rob

> **···**
>
> > On 19 Jun 2020, at 16:31, Martin DeMello \<martindemello@gmail.com\> wrote:
> > 
> > This page has a good overview of the issues around rounding; in particular check out the sections starting from "but being consistent can be bad"
> > 
> > [Rounding Methods](https://www.mathsisfun.com/numbers/rounding-methods.html)
> > 
> > martin
> > 
> > On Fri, Jun 19, 2020 at 1:00 PM Juan DCG \<juandcg314@gmail.com \<mailto:juandcg314@gmail.com\>\> wrote:  
> > Hi,
> > 
> > I'm not a professional mathematical, but when I was a child I remember that the rule applied when round 5 is:
> > 
> > If x \<= 5 then round to the minor  
> > If x \> 5 then round to the high
> > 
> > Then is this example it must be ( following this school rule ):
> > 
> > 1,44999 -\> round(2)= 1,45  
> > 1,45 -\> round(1)= 1,4  
> > 1,4 -\< round= 1
> > 
> > That is the rule I remember.
> > 
> > But now, testing:
> > 
> > gems :001 \> 1.44999.round(3)  
> > =\> 1.45  
> > gems :002 \> 1.45.round(1)  
> > =\> 1.5  
> > gems :003 \> 1.5.round  
> > =\> 2  
> > gems :004 \> 1.44999.round  
> > =\> 1  
> > gems :005 \> 0.5.round  
> > =\> 1
> > 
> > I'm confused where search the official reference to round number, ¿some standard in mathematics ;)?  
> > because irb doesn't round like a school child ( in my school ), although when round complete number "my" rule is applied.
> > 
> > Regards,
> > 
> > El vie., 19 jun. 2020 a las 21:16, Die Optimisten (\<inform@die-optimisten.net \<mailto:inform@die-optimisten.net\>\>) escribió:  
> > Any math-people here, what is correct?
> > 
> > I would say using pencil and paper 1.4499.round(1)=1.5, because you have  
> > to begin with the LSB,  
> > so 1.44999 -\> 1.45 -\> 1.5. I'll ask my friend, what his kids are  
> > learning in school.  
> > (The other question is, if you can trust, that what people are told in  
> > school, is always correct... Buts thats another thread....)
> > 
> > What about the half-options? Seems hard to find anybody who has used /  
> > knows that feature? ;))
> > 
> > Andrew
> > 
> > Unsubscribe: \<mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe\>  
> > \<[http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);
> > 
> > Unsubscribe: \<mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe\>  
> > \<[http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);
> > 
> > Unsubscribe: \<mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe\>  
> > \<[http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);

---

<div class="post-metadata">

**Author:** ![Xavier\_Noria](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/xavier_noria/32/1867_2.png) [@Xavier\_Noria](https://rubytalk.org/u/Xavier_Noria)\
**Post date:** [19 June 2020 21:47 UTC](https://rubytalk.org/t/round/75273/12 "2020-06-19T21:47:54Z")

</div>

Any math-people here, what is correct?

> I would say using pencil and paper 1.4499.round(1)=1.5, because you have  
> to begin with the LSB,

Not really, you only peek at one digit more, as it is. Irrational numbers  
do not even have a "last digit". An irrational number has an infinite  
number of decimals without a repeating pattern, and this property does not  
depend on the base. But you can round π to any number of decimals, for  
example, right?

You can play with this in Wolfram|Alpha \<[https://www.wolframalpha.com](https://www.wolframalpha.com)\>  
issuing the query 1.4499 round to 2 digits  
\<[1.4499 round to 2 digits - Wolfram|Alpha](https://www.wolframalpha.com/input/?i=1.4499+round+to+2+digits&gt;%5C).

> **···**
>
> On Fri, Jun 19, 2020 at 9:16 PM Die Optimisten \<inform@die-optimisten.net\> wrote:

---

<div class="post-metadata">

**Author:** ![Die\_Optimisten](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@Die\_Optimisten](https://rubytalk.org/u/Die_Optimisten)\
**Post date:** [20 June 2020 08:58 UTC](https://rubytalk.org/t/round/75273/13 "2020-06-20T08:58:32Z")

</div>

Hi,  
yes, we know that?! These are the cases, where we all share the same  
opinion.  
2) what about renaming half: up/down to abs\_up/abs\_down (+new up/down:  
round to +-infinite)  
1) Perhaps an additional option: x.round(digits, precise: false) for  
"complete" rounding?  
- Nevertheless it's of intest, what is mathematical correct (which  
should be the default)

Andrew

> **···**
>
> Am 6/19/20 um 9:38 PM schrieb Marc Chanliau:
> 
> > 2.7.1 :001 \> \*1.4567\*.round(\*3\*)  
> > =\> \*1.457\*  
> > 2.7.1 :002 \> \*1.563\*.round(\*2\*)  
> > =\> \*1.56\*  
> > 2.7.1 :003 \> \*1.563\*.round  
> > =\> \*2\*
> > 
> > > On Jun 19, 2020, at 12:15 PM, Die Optimisten \>\> \<inform@die-optimisten.net \<mailto:inform@die-optimisten.net\>\> wrote:
> > > 
> > > Any math-people here, what is correct?
> > > 
> > > I would say using pencil and paper 1.4499.round(1)=1.5, because you have  
> > > to begin with the LSB,  
> > > so 1.44999 -\> 1.45 -\> 1.5. I'll ask my friend, what his kids are  
> > > learning in school.  
> > > (The other question is, if you can trust, that what people are told in  
> > > school, is always correct... Buts thats another thread....)
> > > 
> > > What about the half-options? Seems hard to find anybody who has used /  
> > > knows that feature? ;))
> > > 
> > > Andrew
> > > 
> > > Unsubscribe: \<mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe\>  
> > > \<[http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);
> > 
> > Unsubscribe: \<mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe\>  
> > \<[http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);

---

<div class="post-metadata">

**Author:** ![Die\_Optimisten](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@Die\_Optimisten](https://rubytalk.org/u/Die_Optimisten)\
**Post date:** [20 June 2020 09:17 UTC](https://rubytalk.org/t/round/75273/14 "2020-06-20T09:17:25Z")

</div>

> Hi,  
> yes, we know that?! These are the cases, where we all share the same  
> opinion.  
> 2) what about renaming half: up/down to abs\_up/abs\_down (+new up/down:  
> round to +-infinite)  
> 1) Perhaps an additional option: x.round(digits, precise: false) for  
> "complete" rounding?  
> - Nevertheless it's of intest, what is mathematical correct (which  
> should be the default)

(Sorry, new mails weren't fetched before, I am refering to Marc lines only)

Thanks for the many answers!

So the "big"-math software (besides popular MS$-products - which make up  
/ form the mainstream, also when scientifically wrong...) also involve  
only the [ONE] digit afterward?  
ok, then I would say it's "scientific correct" and standard.  
I personally would prefer rounding "as best as possible" (you only have  
to look at further digits if the relevant digit is 4, so with Mrds? of  
PI-digits these very few additional digits must be used for correct  
rounding 😉

Any opinions to the half-options?

Andrew

> **···**
>
> Am 6/20/20 um 10:58 AM schrieb Die Optimisten:
> 
> > Am 6/19/20 um 9:38 PM schrieb Marc Chanliau:
> > 
> > > 2.7.1 :001 \> \*1.4567\*.round(\*3\*)  
> > > =\> \*1.457\*  
> > > 2.7.1 :002 \> \*1.563\*.round(\*2\*)  
> > > =\> \*1.56\*  
> > > 2.7.1 :003 \> \*1.563\*.round  
> > > =\> \*2\*
> > > 
> > > > On Jun 19, 2020, at 12:15 PM, Die Optimisten \>\>\> \<inform@die-optimisten.net \<mailto:inform@die-optimisten.net\>\> wrote:
> > > > 
> > > > Any math-people here, what is correct?
> > > > 
> > > > I would say using pencil and paper 1.4499.round(1)=1.5, because you have  
> > > > to begin with the LSB,  
> > > > so 1.44999 -\> 1.45 -\> 1.5. I'll ask my friend, what his kids are  
> > > > learning in school.  
> > > > (The other question is, if you can trust, that what people are told in  
> > > > school, is always correct... Buts thats another thread....)
> > > > 
> > > > What about the half-options? Seems hard to find anybody who has used /  
> > > > knows that feature? ;))
> > > > 
> > > > Andrew
> > > > 
> > > > Unsubscribe:  
> > > > \<mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe\>  
> > > > \<[http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);
> > > 
> > > Unsubscribe:\<mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe\>  
> > > \<[http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);
> > 
> > Unsubscribe: \<mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe\>  
> > \<[http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);

---

<div class="post-metadata">

**Author:** ![botp1](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@botp1](https://rubytalk.org/u/botp1)\
**Post date:** [20 June 2020 10:22 UTC](https://rubytalk.org/t/round/75273/15 "2020-06-20T10:22:46Z")

</div>

> I personally would prefer rounding "as best as possible"

as i understand fr this thread, you'd prefer the up or ceiling option, but  
you'll have to test further your use case (wc may not be mathematically or  
scientifically be your taste :),  
eg,

1.44599.round(1,up) =\> 1.5  
1.44599.round(1,ceiling) =\> 1.5

ruby's rounding options support almost all(?) that is stated in wikipedia,  
but you'll have to use bigdecimal (because float does not even come close)

hth  
--botp

ps: just in case, you'd like to test many cases

> > require 'bigdecimal/util'

=\> true

> > numbers

=\> [1.4, 1.44, 1.445, 1.44599]

> > options

=\> [:up, :down, :truncate, :half\_up, :half\_down, :half\_even, :banker,  
:ceiling, :floor]

> > roundings

=\> [1, 2, 3]  
?\> numbers.each do |n|  
?\> roundings.each do |r|  
?\> options.each do |o|  
?\> puts "#{n}.round(#{r},#{o}) =\> #{"%.#{r}f" % n.to\_d.round(r,o)}"  
?\> end  
?\> end

> > end

1.4.round(1,up) =\> 1.4  
1.4.round(1,down) =\> 1.4  
1.4.round(1,truncate) =\> 1.4  
1.4.round(1,half\_up) =\> 1.4  
1.4.round(1,half\_down) =\> 1.4  
1.4.round(1,half\_even) =\> 1.4  
... snip...

> **···**
>
> On Sat, Jun 20, 2020 at 5:17 PM Die Optimisten \<inform@die-optimisten.net\> wrote:

---

<div class="post-metadata">

**Author:** ![Die\_Optimisten](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@Die\_Optimisten](https://rubytalk.org/u/Die_Optimisten)\
**Post date:** [20 June 2020 12:34 UTC](https://rubytalk.org/t/round/75273/16 "2020-06-20T12:34:30Z")

</div>

Hi,  
no, I just want better "precision" -- recursive x.round(n): i=100;  
x=x.round(i); i--; until i==n

Should Bigdeci beeing used anymore (deprecated, because included into  
Float ??)

Andrew

> **···**
>
> Am 6/20/20 um 12:22 PM schrieb botp:
> 
> > On Sat, Jun 20, 2020 at 5:17 PM Die Optimisten \> \<inform@die-optimisten.net \<mailto:inform@die-optimisten.net\>\> wrote:
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;I personally would prefer rounding "as best as possible"
> > 
> > as i understand fr this thread, you'd prefer the up or ceiling option,  
> > but you'll have to test further your use case (wc may not be  
> > mathematically or scientifically be your taste :),  
> > eg,
> > 
> > 1.44599.round(1,up) =\> 1.5  
> > 1.44599.round(1,ceiling) =\> 1.5
> > 
> > ruby's rounding options support almost all(?) that is stated in  
> > wikipedia, but you'll have to use bigdecimal (because float does not  
> > even come close)
> > 
> > hth  
> > --botp
> > 
> > ps: just in case, you'd like to test many cases
> > 
> > \>\> require 'bigdecimal/util'  
> > =\> true  
> > \>\> numbers  
> > =\> [1.4, 1.44, 1.445, 1.44599]  
> > \>\> options  
> > =\> [:up, :down, :truncate, :half\_up, :half\_down, :half\_even, :banker,  
> > :ceiling, :floor]  
> > \>\> roundings  
> > =\> [1, 2, 3]  
> > ?\> numbers.each do |n|  
> > ?\> roundings.each do |r|  
> > ?\> options.each do |o|  
> > ?\> puts "#{n}.round(#{r},#{o}) =\> #{"%.#{r}f" % n.to\_d.round(r,o)}"  
> > ?\> end  
> > ?\> end  
> > \>\> end  
> > 1.4.round(1,up) =\> 1.4  
> > 1.4.round(1,down) =\> 1.4  
> > 1.4.round(1,truncate) =\> 1.4  
> > 1.4.round(1,half\_up) =\> 1.4  
> > 1.4.round(1,half\_down) =\> 1.4  
> > 1.4.round(1,half\_even) =\> 1.4  
> > ... snip...
> > 
> > Unsubscribe: \<mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe\>  
> > \<[http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);

---

<div class="post-metadata">

**Author:** ![Tom\_Lord](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/tom_lord/32/2215_2.png) [@Tom\_Lord](https://rubytalk.org/u/Tom_Lord)\
**Post date:** [20 June 2020 12:41 UTC](https://rubytalk.org/t/round/75273/17 "2020-06-20T12:41:43Z")

</div>

There are several standard forms of rounding, as mentioned already.

You can round up (ceiling), down (floor), or towards the nearest interval - with special handling of what to do halfway.

However, it is incorrect to round 1.4445 —\> 1.5, unless your rule would also round 1.4001 —\> 1.5.  
This form of rounding would be called “fraud”.

1.4445 is closer to 1.4 than to 1.5.  
It is not “more precise” to round it up.

… Likewise, it is most likely incorrect to round 1.44599 —\> 1.5.

> **···**
>
> > On 20 Jun 2020, at 13:34, Die Optimisten \<inform@die-optimisten.net\> wrote:
> > 
> > Hi,  
> > no, I just want better "precision" -- recursive x.round(n): i=100; x=x.round(i); i--; until i==n
> > 
> > Should Bigdeci beeing used anymore (deprecated, because included into Float ??)
> > 
> > Andrew
> > 
> > Am 6/20/20 um 12:22 PM schrieb botp:
> > 
> > > On Sat, Jun 20, 2020 at 5:17 PM Die Optimisten \<inform@die-optimisten.net \<mailto:inform@die-optimisten.net\>\> wrote:  
> > > I personally would prefer rounding "as best as possible"
> > > 
> > > as i understand fr this thread, you'd prefer the up or ceiling option, but you'll have to test further your use case (wc may not be mathematically or scientifically be your taste :),  
> > > eg,
> > > 
> > > 1.44599.round(1,up) =\> 1.5  
> > > 1.44599.round(1,ceiling) =\> 1.5
> > > 
> > > ruby's rounding options support almost all(?) that is stated in wikipedia, but you'll have to use bigdecimal (because float does not even come close)
> > > 
> > > hth  
> > > --botp
> > > 
> > > ps: just in case, you'd like to test many cases
> > > 
> > > \>\> require 'bigdecimal/util'  
> > > =\> true  
> > > \>\> numbers  
> > > =\> [1.4, 1.44, 1.445, 1.44599]  
> > > \>\> options  
> > > =\> [:up, :down, :truncate, :half\_up, :half\_down, :half\_even, :banker, :ceiling, :floor]  
> > > \>\> roundings  
> > > =\> [1, 2, 3]  
> > > ?\> numbers.each do |n|  
> > > ?\> roundings.each do |r|  
> > > ?\> options.each do |o|  
> > > ?\> puts "#{n}.round(#{r},#{o}) =\> #{"%.#{r}f" % n.to\_d.round(r,o)}"  
> > > ?\> end  
> > > ?\> end  
> > > \>\> end  
> > > 1.4.round(1,up) =\> 1.4  
> > > 1.4.round(1,down) =\> 1.4  
> > > 1.4.round(1,truncate) =\> 1.4  
> > > 1.4.round(1,half\_up) =\> 1.4  
> > > 1.4.round(1,half\_down) =\> 1.4  
> > > 1.4.round(1,half\_even) =\> 1.4  
> > > ... snip...
> > > 
> > > Unsubscribe: \<mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe\> \<mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe\>  
> > > \<[http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt); \<[http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);
> > 
> > Unsubscribe: \<mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe\>  
> > \<[http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);

---

<div class="post-metadata">

**Author:** ![Die\_Optimisten](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@Die\_Optimisten](https://rubytalk.org/u/Die_Optimisten)\
**Post date:** [20 June 2020 13:21 UTC](https://rubytalk.org/t/round/75273/18 "2020-06-20T13:21:13Z")

</div>

> There are several standard forms of rounding, as mentioned already.
> 
> You can round up (ceiling), down (floor), or towards the nearest  
> interval - with special handling of what to do halfway.
> 
> However, it is \*incorrect\* to round 1.4445 —\> 1.5, unless your rule  
> would also round 1.4001 —\> 1.5.  
> This form of rounding would be called “fraud”.
> 
> 1.4445 is closer to 1.4 than to 1.5.  
> It is not “more precise” to round it up.

ok, thats persuasive!  
Besides, "recursive round" looks evident, too! - Both are logical (look  
correct), but only one can be correct...  
Seems my mathematical understanding is inconsistent! - Anyone who can  
explain that in detail?  
- Or do I need a psychiatrist??? 😉

What sense does it make to round 1.40001 -\> 1.5? (any use-cases?)

Shall Bigdeci be used? I remember I read sg of "deprecicated"

> **···**
>
> Am 6/20/20 um 2:41 PM schrieb Tom Lord:
> 
> > … Likewise, it is most likely incorrect to round 1.44599 —\> 1.5.

---

<div class="post-metadata">

**Author:** ![Jack\_Royal-Gordon](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/jack_royal-gordon/32/2187_2.png) [@Jack\_Royal-Gordon](https://rubytalk.org/u/Jack_Royal-Gordon)\
**Post date:** [20 June 2020 13:45 UTC](https://rubytalk.org/t/round/75273/19 "2020-06-20T13:45:14Z")

</div>

Put another way, anything \> 1.40 and \< 1.45 rounds down to 1.4; is 1.4495 \< 1.45? Why yes, it is.

It doesn’t seem too difficult to me; if it’s less than half-way to the next higher value, then round it down. And 1.4495 is closer to 1.4 than to 1.5. Don’t let the less important digits to the right influence your thinking — being to the right, they are “less significant” in more than just name.

> **···**
>
> > On Jun 20, 2020, at 6:21 AM, Die Optimisten \<inform@die-optimisten.net\> wrote:
> > 
> > Am 6/20/20 um 2:41 PM schrieb Tom Lord:
> > 
> > > There are several standard forms of rounding, as mentioned already.
> > > 
> > > You can round up (ceiling), down (floor), or towards the nearest interval - with special handling of what to do halfway.
> > > 
> > > However, it is incorrect to round 1.4445 —\> 1.5, unless your rule would also round 1.4001 —\> 1.5.  
> > > This form of rounding would be called “fraud”.
> > > 
> > > 1.4445 is closer to 1.4 than to 1.5.  
> > > It is not “more precise” to round it up.
> > 
> > ok, thats persuasive!  
> > Besides, "recursive round" looks evident, too! - Both are logical (look correct), but only one can be correct...  
> > Seems my mathematical understanding is inconsistent! - Anyone who can explain that in detail?  
> > - Or do I need a psychiatrist??? 😉
> > 
> > What sense does it make to round 1.40001 -\> 1.5? (any use-cases?)
> > 
> > Shall Bigdeci be used? I remember I read sg of "deprecicated"
> > 
> > > … Likewise, it is most likely incorrect to round 1.44599 —\> 1.5.
> > 
> > Unsubscribe: \<mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe\>  
> > \<[http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);

---

<div class="post-metadata">

**Author:** ![RDSM](https://avatars.discourse-cdn.com/v4/letter/r/50afbb/32.png) [@RDSM](https://rubytalk.org/u/RDSM)\
**Post date:** [20 June 2020 13:47 UTC](https://rubytalk.org/t/round/75273/20 "2020-06-20T13:47:09Z")

</div>

Why do recursive rounding? It is completely non-sense, every time you are rounding you are losing some information, since you already do have the information why lose it by doing several rounds of rounding...

Also if want a "mathematical source" , how about using Wolfram alpha?  
[Round[1.44999,0.1] - Wolfram|Alpha](https://www.wolframalpha.com/input/?i=Round%5B1.44999%2C0.1%5D&wal=header)

Unless you specify what kind of rounding you want (as provided by bigDecimal) it would be surprising to see anyone rounding up a number a number smaller than half...

Also they , not surprisingly, define on their documentation rounding as getting the nearest number "  
Round[x,a]  
rounds to the nearest multiple of a.  
“

> **···**
>
> On 20 Jun 2020 10:21 -0300, Die Optimisten \<inform@die-optimisten.net\>, wrote:
> 
> > Am 6/20/20 um 2:41 PM schrieb Tom Lord:  
> > \> There are several standard forms of rounding, as mentioned already.  
> > \>  
> > \> You can round up (ceiling), down (floor), or towards the nearest interval - with special handling of what to do halfway.  
> > \>  
> > \> However, it is incorrect to round 1.4445 —\> 1.5, unless your rule would also round 1.4001 —\> 1.5.  
> > \> This form of rounding would be called “fraud”.  
> > \>  
> > \> 1.4445 is closer to 1.4 than to 1.5.  
> > \> It is not “more precise” to round it up.  
> > ok, thats persuasive!  
> > Besides, "recursive round" looks evident, too! - Both are logical (look correct), but only one can be correct...  
> > Seems my mathematical understanding is inconsistent! - Anyone who can explain that in detail?  
> > - Or do I need a psychiatrist??? 😉  
> > What sense does it make to round 1.40001 -\> 1.5? (any use-cases?)  
> > Shall Bigdeci be used? I remember I read sg of "deprecicated"  
> > \>  
> > \> … Likewise, it is most likely incorrect to round 1.44599 —\> 1.5.
> > 
> > Unsubscribe: \<mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe\>  
> > \<[http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);

[Next page](https://rubytalk.org/t/round/75273.md?page=2)
