Reputation: 589
var PI = 3.14159265358979323846;
var intelect = 33;
var ageInDays = 54
document.write("answer: " + Math.sin(ageInDays*2*PI/intelect));
Is it possible to round when using Math.sin
?
Upvotes: 1
Views: 172
Reputation: 82794
What hinders you to use Math.round
(or Math.floor
, Math.ceil
)?
var PI = 3.14159265358979323846;
var intelect = 33;
var ageInDays = 54
document.write("answer: " + Math.floor(Math.sin(ageInDays*2*PI/intelect)));
Upvotes: 0
Reputation: 18354
You are looking for toFixed
:
Math.sin(ageInDays*2*PI/intelect).toFixed(2)); //Ans: 0.76
Upvotes: 6
Reputation: 12618
Sure you can;
var calc = Math.sin(ageInDays*2*Math.PI/intellect);
document.write(Math.round(calc));
Or, alternatively:
document.write("answer: " + Math.round(Math.sin(ageInDays*2*PI/intellect)));
There is no need to define your own PI, javascript's math object has a property for that.
Upvotes: 1