Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-15256

Why I can't use parseInt on NumberLong but arithmetics can?

    • Type: Icon: Question Question
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.4.9, 2.6.3
    • Component/s: JavaScript
    • Labels:
      None

      For some reason, using parseInt or parseFloat on NumberLong gives NaN, but using arithmetic operations converts them to ints/floats without issues?

      See the following:

      > parseInt(NumberLong(2))
      NaN
      > parseFloat(NumberLong(2))
      NaN
      > NumberLong(2) + NumberLong(0)
      2 <-- this is an int, not NumberLong
      

      So this obviously works:

      > parseInt(NumberLong(2) + NumberLong(0))
      2
      

      Tested on Mongo 2.4.9 and 2.6.3. This seems like a completely illogical behaviour. This became important since PHP driver converts every number to NumberFloat.

            Assignee:
            ramon.fernandez@mongodb.com Ramon Fernandez Marina
            Reporter:
            paulina Paulina Budzo?
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: