Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/432.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何连接。(点)带有javascript中的数字_Javascript_Html_Vue.js_Vuejs2_Vue Component - Fatal编程技术网

如何连接。(点)带有javascript中的数字

如何连接。(点)带有javascript中的数字,javascript,html,vue.js,vuejs2,vue-component,Javascript,Html,Vue.js,Vuejs2,Vue Component,嗨,我用html创建了visual calc 它看起来是这样的 | 1 | 2 | 3 | | 4 | 5 | 6 | | 7 | 8 | 9 | | | . | | 我在单击每个html元素时创建了一个名为number()的函数 就是这个 number(number) { this.total_quantity_discount_price = this.total_quantity_discount_price+''+number; this.

嗨,我用html创建了visual calc 它看起来是这样的

| 1  | 2  | 3 | 
| 4  | 5  | 6 | 
| 7  | 8  | 9 | 
|    | .  |   |
我在单击每个html元素时创建了一个名为
number()
的函数 就是这个

number(number)
{
    this.total_quantity_discount_price = this.total_quantity_discount_price+''+number;
    this.total_quantity_discount_price = parseFloat(this.total_quantity_discount_price);
},
对于数字
0123456789
一切正常,但我的
问题是如何将
添加到
中。总数量\u折扣\u价格
我的意思是我怎样才能把数字加上10.555或55.648等。。
谢谢..

像构造函数一样使用
Number

this.total_quantity_discount_price = Number(this.total_quantity_discount_price+''+number);
设n=Number(4+'.+5)
//n是一个数字,您可以将它添加到另一个数字中
console.log(n)
console.log(n+1)

console.log(n-3)
您可以像这样使用
+
操作符:

const n='4'+'.+'3'+'4';
控制台日志(+n);
控制台日志(+n+1);

控制台日志(+n-1)
您可以将所有内容合并在一起,并使用
新函数()对其进行解析。

let result=”“;
让calc=document.getElementById(“计算”);
让输出=document.getElementById(“结果”);
document.queryselectoral(“按钮”).forEach(el=>{
el.addEventListener(“单击”,()=>{
结果+=el.innerHTML;
output.innerHTML=结果;
})
})
函数render(){
让calcResult=解释(结果);
output.innerHTML=calcResult;
}
函数getResult(){
output.innerHTML=解释(结果);
}
函数clearResult(){
output.innerHTML=“”;
结果=”;
}
函数返回(){
结果=结果切片(0,-1);
output.innerHTML=结果;
}
函数解释(str){
返回新函数(`return${str}`)()
}
.buttonholder{
显示器:flex;
柔性流动:包裹;
宽度:170px;
}
钮扣{
显示:块;
保证金:2倍;
填充:15px;
}
.盒子{
光标:指针;
背景:黑色;
颜色:白色;
填充:10px;
利润率:10px;
}
#结果{
背景:绿色;
颜色:白色;
填充:10px;
}

1.
2.
3.
4.
5.
6.
7.
8.
9
.
+
-
*
/