How to convert string to double?

2,818 views
Skip to first unread message

rl

unread,
Mar 24, 2012, 2:53:45 PM3/24/12
to mongod...@googlegroups.com
I am trying to convert strings to doubles in a script but I am getting an error.  What do I need to correct?

mongo convert.js generates "ReferenceError: parseDouble is not defined"

convert.js:

db.mycollection.find().forEach(function(doc) {
doc.vals = [parseDouble(doc.minVal), parseDouble(doc.maxVal)];
db.mycollection.save(doc);
    })


Thanks in advance!


Scott Hernandez

unread,
Mar 24, 2012, 3:08:13 PM3/24/12
to mongod...@googlegroups.com
I think you want parseFloat(), since there is no parseDouble() unless
you want to write it yourself:
http://royaltutorials.com/javascript-parsedouble/

> --
> You received this message because you are subscribed to the Google Groups
> "mongodb-user" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/mongodb-user/-/FXC8jpPpcmMJ.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to
> mongodb-user...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/mongodb-user?hl=en.

Robert La Ferla

unread,
Mar 24, 2012, 4:43:07 PM3/24/12
to mongod...@googlegroups.com
Thanks. The examples I saw on stackoverflow.com used parseDouble() (bet they didn't test before posting). I tried and parseFloat() works!
Reply all
Reply to author
Forward
0 new messages