I am using bigDecimal.js:
https://github.com/iriscouch/bigdecimal.js
in my node.js project server side with no problems however when I try the same on the client I can’t seem to reference the bigDecimal object correctly. On the github page it has a link:
http://jhs.iriscouch.com/demo/_design/bigdecimal/_show/ui?e=321.4567890*123456789.123456789987654321
I have a link to bigdecimal.js in my html:
<script src="/javascripts/bigdecimal.js" type="text/javascript"></script>
and the script is definitely there as I can navigate to it in chrome.
my code looks like this:
var bd = {"BigDecimal":BigDecimal, "BigInteger":BigInteger, "RoundingMode":RoundingMode};
var bigDeletedVideoID = bd.BigInteger('9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999');
var bigLowNum = bd.BigInteger('1');
alert(bigDeletedVideoID.subtract(bigLowNum));
But I am getting an error in chrome on the first line saying:
BigDecimal is not defined.
Has anybody had any experience with using BigDecimal and how to do this on a javascript web client?
UPDATED:
I tested the code on localhost i.e. referencing the .js library like so:
http://localhost:11709/javascripts/bigdecimal.js
and I get the alert message appearing correctly.
But when I upload the site to the live server and now it turns into:
http://pazooza.azurewebsites.net/javascripts/bigdecimal.js
All of a sudden I get 2 errors in particular:
- unexpected identifier bigdecimal.js line 293
- BigDecimal is not defined
Why come it works on localhost and not on the live site???
From: Load javascript via Firebug console
There doesn’t seem to be any namespace conflict as I suspected before rewriting this answer:
Instead one has to be very precise of not using the symbol ‘BigDecimal’ before the js page has been loaded…
This is typically handled by onload events.
Original suggestion was using node.js framework or assuming namespace BD
as suggested by https://github.com/iriscouch/bigdecimal.js