0

I Have some Formulas in Javascript and trying to format them but unable to do that . Here is my JS code from which i am trying to make calculations I have these two variable from which i get input and then make calculations

var pkrusd;
var pkrusd = parseFloat(document.getElementById('txtpkrusd').value, 10); 
var ratelb;
ratelb = parseFloat(document.getElementById('txtRatelb').value, 10);

And here are my formulas from which i show results

var res;
res=roundNumber((pkrusd*ratelb)/100.00,2);
document.getElementById('txtF5').value = addCommas(res);
//Per Kg
var perkg=((pkrusd*ratelb)/100.00)*2.20462262184878;
document.getElementById('txtperkg').value=addCommas(roundNumber(perkg,2));
//RS Per Maund
var perMaund=roundNumber((((pkrusd*ratelb)/100.00)*2.20462262184878)*37.3242,2);
document.getElementById('txtperMaund').value=addCommas(perMaund);

Problem is that when i res formula and values pkrusd and ratelb are 91 and 100 and formula for these is (91*100)/100 the result is 91 but i want to set some formating that should be displayed as 91.00 and when values are (91*250)*100 then result is 227.5 but i want to display as 227.50.If there any possibilty for this then please help me to do this

1 Answer 1

1

Have a look at toFixed()

Example:

var n=91;
alert(n.toFixed(2));

That outputs 91.00

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.