I am having trouble using numeral.js in the script part of my jade file.
I have numeral in locals as such:
app.locals.numeral = require('numeral');
Then in my jade file I want to numeral a variable and format it to dollars, but every time I do it it gets $0.00 so it seems to not be getting the variable correctly. if i just hard code a number is to works great.
example:
script.
$('#calculate').click(function() {
var contracts = 0;
var premium = 0;
var size = 0;
var proceeds = 0;
var myresult = 0;
contracts = $('#contracts').val();
premium = $('#premium').val();
size = $('input:radio[name=size]:checked').val();
myresult = (contracts * premium * size);
proceeds = "#{numeral(" + myresult + ").format('$0.00')}";
alert(proceeds);
});
so specific line I'm having trouble with is:
proceeds = "#{numeral(" + myresult + ").format('$0.00')}";
Individually all the numbers work and if I don't use numeral I get the right outcome, but as soon as I numeral I get $0.00.
Not sure what how to get it to see the variable myresult, I've tried many combinations. Any help greatly appreciated!
I ended up giving up accessing numeral this way and for this one page I included the entire js file in a script tag like such:
script(src='/javascripts/numeral.min.js')
And then:
proceeds = numeral(myresult).format('$0.00');
Not sure this is ideal but it works.