gpt4 book ai didi

html - AngularJS 平方根

转载 作者:太空宇宙 更新时间:2023-11-03 17:32:21 25 4
gpt4 key购买 nike

我正在使用 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();

关于html - AngularJS 平方根,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30311775/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com