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

how to compare two NumberDecimal digits in javascript

    • Type: Icon: Question Question
    • Resolution: Community Answered
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Fully Compatible
    • 15

      Hi, 

          I am using map-reduce and in the map function I am trying to find out all objects with its value = or > or < a given decimal value. those objects are all NumberDecimal  ones. note for some reason, I can't use aggregation operation.

          My question is:  how can I compare two NumberDecimal digits in Javascripts? Does Mongo provide a function like compareTo() that I can use?

           e.g   var X=new NumberDecimal("100");
          var Y=new NumberDecimal("100.0");

      in JavaScript, X== Y is false.

      Perhaps I should converse the two to BigDecimal type and then do comparation? As I know, JavaScript doesn't have a native Decimal Type, and I have to use a library which define BigDecimal.

      Is it possible for to use this library in map-reduce operation? How should achieve this?

      by the way, I found the a lib who defines the bigDecimal : https://github.com/royNiladri/js-big-decimal#readme

      but it requires me to install it like this: npm install --save js-big-decimal and then introduce it like this: var bigDecimal = require('js-big-decimal');

      but I think I can't install it in mongo server.

      it also suggest for web , I can do like this:

      <script src="node_modules/js-big-decimal/dist/web/js-big-decimal.min.js"></script>

      but I don't think It is applicable for me.

      Is there any good suggestion for me to achieve my goal? Note I need to compare the two digits by <, =, and >.

       

       

            Assignee:
            dmitry.agranat@mongodb.com Dmitry Agranat
            Reporter:
            winnie.wu@quest.com winnie wu
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: