Number underscored gone wrong

Dear ruby fans...

Just a quick question: I always thought underscores in numbers were ignored, like 100_000, 10_00 or 666_6.

Buuut: did anyone of you tried to do following?

0_50

WTH :slight_smile:

Really - try it :slight_smile:

Would be great if someone could answer why this is not working as I imagined? :slight_smile:

Have a nice afternoon!

When you prefix a number with a 0, it's interpreted in octal. Hence, 5 * 8
= 40.

路路路

On Tue, Sep 17, 2019 at 11:13 AM Peter L <office@lampesberger.net> wrote:

Dear ruby fans...

Just a quick question: I always thought underscores in numbers were
ignored, like 100_000, 10_00 or 666_6.

Buuut: did anyone of you tried to do following?

> 0_50

WTH :slight_smile:

Really - try it :slight_smile:

Would be great if someone could answer why this is not working as I
imagined? :slight_smile:

Have a nice afternoon!

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

--
*Kevin D. Deisz*
CTO, CultureHQ <https://www.culturehq.com>

Any number with a leading 0 is treated as an octal representation rather
than decimal.

[1] pry(main)> 0_50
=> 40
[2] pry(main)> 050
=> 40
[3] pry(main)> 050.to_s(10)
=> "40"
[4] pry(main)> 050.to_s(8)
=> "50"

-Jeremy

路路路

On Tue, Sep 17, 2019 at 10:13 AM Peter L <office@lampesberger.net> wrote:

Dear ruby fans...

Just a quick question: I always thought underscores in numbers were
ignored, like 100_000, 10_00 or 666_6.

Buuut: did anyone of you tried to do following?

> 0_50

WTH :slight_smile:

Really - try it :slight_smile:

Would be great if someone could answer why this is not working as I
imagined? :slight_smile:

Have a nice afternoon!

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

Ahhh, I see... Weird though :smiley:

Thank you!

路路路

Am 17.09.2019 um 17:15 schrieb Jeremy Bopp <jeremy@bopp.net <mailto:jeremy@bopp.net>>:

Any number with a leading 0 is treated as an octal representation rather than decimal.

[1] pry(main)> 0_50
=> 40
[2] pry(main)> 050
=> 40
[3] pry(main)> 050.to_s(10)
=> "40"
[4] pry(main)> 050.to_s(8)
=> "50"

-Jeremy

On Tue, Sep 17, 2019 at 10:13 AM Peter L <office@lampesberger.net <mailto:office@lampesberger.net>> wrote:
Dear ruby fans...

Just a quick question: I always thought underscores in numbers were ignored, like 100_000, 10_00 or 666_6.

Buuut: did anyone of you tried to do following?

> 0_50

WTH :slight_smile:

Really - try it :slight_smile:

Would be great if someone could answer why this is not working as I imagined? :slight_smile:

Have a nice afternoon!

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

And what if I write not one but two zeroes in front of it? Will it turn
into a black woman?

It must be what happened to 007

Mage

路路路

On Tue, Sep 17, 2019 at 5:16 PM Jeremy Bopp <jeremy@bopp.net> wrote:

Any number with a leading 0 is treated as an octal representation rather
than decimal.

[1] pry(main)> 0_50
=> 40
[2] pry(main)> 050
=> 40
[3] pry(main)> 050.to_s(10)
=> "40"
[4] pry(main)> 050.to_s(8)
=> "50"

-Jeremy

On Tue, Sep 17, 2019 at 10:13 AM Peter L <office@lampesberger.net> wrote:

Dear ruby fans...

Just a quick question: I always thought underscores in numbers were
ignored, like 100_000, 10_00 or 666_6.

Buuut: did anyone of you tried to do following?

> 0_50

WTH :slight_smile:

Really - try it :slight_smile:

Would be great if someone could answer why this is not working as I
imagined? :slight_smile:

Have a nice afternoon!

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

What the fuck?

路路路

On Sep 17, 2019, at 09:08, Mage <mage@mage.gold> wrote:

And what if I write not one but two zeroes in front of it? Will it turn into a black woman?