Skip to content

Belt.Int.fromString silently throws away part of input #3732

Closed
@RasmusKlett

Description

@RasmusKlett

I encountered some very surprising behaviour using Belt.Int.fromString. If given the string representation of a floating point number, it will silently ignore anything beyond the decimal point.

Looking at the source, it turns out fromString is simply wrapping the Javascript parseInt. This is a very quirky Javascript-esque function, and in my opinion does not deserve a place in Belt.

Examples of surprising behaviour:

"15.9" -> 15      // The ".9" is ignored
"15e99" -> 15     // The "e99" is ignored
"   15" -> 15     // The whitespace is ignored - maybe fine?

I suggest that at least the first two should result in None, since the full string could not be parsed. I find it convenient that leading whitespace is automatically stripped, but some might prefer strict None behaviour in this case as well.

Please - let us not repeat the mistakes of Javascript just because it is convenient to implement.

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleOld issues that went stale

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions