AngularJS 平方根
AngularJS square root
我正在使用 HTML + CSS + AngularJS 制作一个简单的计算器。一切正常,但我想添加一个 SquareRoot 函数。
这是一些代码:
function _solve(){
switch(_state) {
case 'ADD':
_total += parseFloat($scope.console);
$scope.console = 0;
break; //similar for the rest of the operations
$scope.add = function() {
_solve();
_state = 'ADD';} //this is how i call the function.
这是我对 Sqrt 的想法,但我认为不太好:
$scope.getSqrt = function() {
$scope.console = (parseFloat($scope.console) * Math.Sqrt).toString();}
Math.sqrt 是一个函数,这意味着您需要将要应用该函数的数字放在括号内,例如
Math.sqrt(parseFloat($scope.console)).toString();
您需要将希望从中提取平方根的数字作为参数提供给 Math.sqrt()
函数,例如:
Math.sqrt(parseFloat($scope.console).toString();
我正在使用 HTML + CSS + AngularJS 制作一个简单的计算器。一切正常,但我想添加一个 SquareRoot 函数。 这是一些代码:
function _solve(){
switch(_state) {
case 'ADD':
_total += parseFloat($scope.console);
$scope.console = 0;
break; //similar for the rest of the operations
$scope.add = function() {
_solve();
_state = 'ADD';} //this is how i call the function.
这是我对 Sqrt 的想法,但我认为不太好:
$scope.getSqrt = function() {
$scope.console = (parseFloat($scope.console) * Math.Sqrt).toString();}
Math.sqrt 是一个函数,这意味着您需要将要应用该函数的数字放在括号内,例如
Math.sqrt(parseFloat($scope.console)).toString();
您需要将希望从中提取平方根的数字作为参数提供给 Math.sqrt()
函数,例如:
Math.sqrt(parseFloat($scope.console).toString();