How to write Mathematical formula with “^” (caret) in JavaScript?

拜拜、爱过 提交于 2019-12-31 02:58:11

问题


I need some help how to make this math formula in javascript. i have tried searching but couldn't really find cause i dont even know what ^ is called in English.

Thanks in advance

Math.floor(20*(1.1^(x-10)));

回答1:


Math.floor(20*(Math.pow(1.1, (x-10))));



回答2:


^ is the bitwise XOR operator - not what you want. Use the Math.pow function for exponentiation:

Math.floor( 20 * (Math.pow(1.1, x - 10)) );

Set this up in a function so you can use x for whatever value it may be:

var eq = function(x) {
    return Math.floor( 20 * (Math.pow(1.1, x - 10)) );
};



回答3:


Math.pow() is what you are looking for.

^, as used in other languages, is called the power or exponential operator, but in Javascript, it serves a different purpose, it is the bitwise XOR operator.




回答4:


Math.floor(20*(Math.pow(1.1, x - 10)));


来源:https://stackoverflow.com/questions/14570889/how-to-write-mathematical-formula-with-caret-in-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!