[SERVER-9684] parseInt(NumberLong()) Creates NaN Created: 14/May/13  Updated: 10/Dec/14  Resolved: 14/May/13

Status: Closed
Project: Core Server
Component/s: JavaScript
Affects Version/s: 2.4.3
Fix Version/s: None

Type: Bug Priority: Critical - P2
Reporter: chuck reeves Assignee: Unassigned
Resolution: Done Votes: 0
Labels: bson, javascript, parser, v8
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

CentOs 6.3 2.6.32-279.el6.x86_64 #1 SMP Fri Jun 22 12:19:21 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
And
Windows 7


Backwards Compatibility: Major Change
Operating System: ALL
Steps To Reproduce:

x = NumberLong(5)
parseInt

Participants:

 Description   

When trying to parseInt on a bson NumberLong, the result will be NaN instead of a number



 Comments   
Comment by chuck reeves [ 14/May/13 ]

OK thanks for clarifying.

Comment by Andy Schwerin [ 14/May/13 ]

The parseInt() function parses strings into integers. The NumberLong() constructor doesn't return a string, but an object. Per the ECMAScript standard (http://www.ecma-international.org/ecma-262/5.1/#sec-15.1.2.2), parseInt first converts the object to a string via toString(), which for NumberLong produces "NumberLong(" followed by some integer characters followed by ")". Since the first character is not a base-10 digit and no radix is specified, parseInt returns NaN.

Generated at Thu Feb 08 03:21:09 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.