Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8378749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:59:56+00:00 2026-06-09T15:59:56+00:00

I’ve been wrestling with my limited knowledge of real programming and need some help…

  • 0

I’ve been wrestling with my limited knowledge of real programming and need some help…

From within node.js and saving into MongoDB (using the native driver) I need to index and search some long numbers.

An example:

87 / 53

On 64-bit windows calculator this is:

1.6415094339622641509433962264151

I run this in node.js:

var answer = 87 / 53;
console.log(answer);

and I get:

1.6415094339622642

my understanding is because node.js only runs 32-bit, we don’t get the precision needed.

So, I plugged in the node-bigint library which wraps libgmp to do big number math using strings…

Now it is:

var bigint = require('bigint');
var top = bigint('8700000000000000000000000000000000000');
var bottom = bigint(53);
var answer = top.div(bottom);
console.log(answer.toString());

I’ve padded with zeros to remove the floating point (easier – I only need to compare the numbers i.e. bigger than smaller than)…

This code yields:

'164150943396226415094339622641509433'

Great – I’ve got more accuracy than the windows calculator : )

Problem is, this number is currently a string – I’m saving the string to Mongo and doing a query like:

{thenumber:{'$gt':'164150943396226415094339622641509433'}}

I.e. I’m comparing strings against strings. This works OK because I’ve padded them all the same.

The question is – is this the best way (i.e. strings) to store and search values or would converting them to 64 bit Long’s be faster for indexing and searching…

If the answer is ‘Use Longs they are faster’ I cannot for the life of me (after lots of Googling) figure out how to turn the string above into a native Mongo Long data type (with the low bits and high bits) – please help out an out of his depth programmer : )

Follow Up:

Reading Long DataType manual for the driver it has this method:

Long.fromBits(lowBits, highBits)

So targeted question – how do I turn a string that represents a 64-bit integer into these low and high bits for the Long to save… Also – is this quicker to search than a string?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:59:57+00:00Added an answer on June 9, 2026 at 3:59 pm

    Use Long.fromString to convert a string into a MongoDB Long:

    var Long = require('mongodb').Long;
    var long = Long.fromString(str, 10);
    

    Second EDIT – Actually, this is the right answer for a string containing a signed 64-bit integer. The problem is that your string of '164150943396226415094339622641509433' is too large to be stored as a 64-bit signed integer. The largest value you can use is (2^63 – 1) or 9223372036854775807.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I don't have much knowledge about the IPv6 protocol, so sorry if the question
Does anyone know how can I replace this 2 symbol below from the string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.