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

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

    XMLWordPrintableJSON

Details

    • Icon: Question Question
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • 2.4.9, 2.6.3
    • JavaScript
    • None

    Description

      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.

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: