Project

General

Profile

Actions

Bug #13088

closed

Strange behavior in String.to_i

Added by mfbmina (Matheus Mina) over 7 years ago. Updated over 7 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:78907]

Description

When I try convert a string to integer using .to_i method it has a strange behavior.

It converts the first number in the string to integer. Is it correct?

I think the expected behavior should be convert to a integer if it has only numbers and return 0 if has a non-digit char on it.

Thank you!


Files

Screen Shot 2016-12-29 at 08.58.11.png (32.5 KB) Screen Shot 2016-12-29 at 08.58.11.png mfbmina (Matheus Mina), 12/29/2016 11:07 AM

Updated by nobu (Nobuyoshi Nakada) over 7 years ago

  • Status changed from Open to Rejected

Matheus Mina wrote:

It converts the first number in the string to integer. Is it correct?

Yes.
http://ruby-doc.org/core-2.4.0/String.html#method-i-to_i

Actions

Also available in: Atom PDF

Like0
Like0