Как добавить операции с дробными числами в калькулятор?
<html>
<head>
<style>
.main-label {color:red;}
li {color:blue;}
</style>
<script type="text/javascript" src="jquery-3.1.0.js"></script>
<script type="text/javascript">
leftPart = '';
rightPart = '';
command='';
result = '0';
currentOperand = 'left';
function digitPress(elem){
if (currentOperand=='left'){
leftPart = leftPart+elem.value;
}
else{
rightPart = rightPart+elem.value;
}
$('#result').val($('#result').val()+elem.value);
var tmp = '';
}
function commandPress(elem){
if(leftPart==''){
leftPart='0';
}
$('#result').val($('#result').val()+elem.value);
command=elem.id;
currentOperand='right';
}
function doCalc(){
switch(command){
case 'plus':
result = parseInt(leftPart)+parseInt(rightPart);
break;
case 'minus':
result = parseInt(leftPart)-parseInt(rightPart);
break;
case 'star':
result = parseInt(leftPart)*parseInt(rightPart);
break;
case 'division':
result = parseInt(leftPart)/parseInt(rightPart);
break;
}
leftPart = result;
currentOperand = 'left';
rightPart = '';
$('#result').val(result);
}
</script>
</head>
<body>
<div class='main-label'>Результат</div>
<input id='result'></input><button id='calc' onclick='doCalc()'>=</button>
<div class='main-label'>Табличный вариант</div>
<table>
<!--<tr>
<td id='minus'>-</td><td id='star'>*</td><td id='div'>/</td>
</tr>-->
<tr>
<td><button id='t1' value='1' onclick='digitPress(this)'>1</button></td>
<td><button id='t2' value='2' onclick='digitPress(this)'>2</button></td>
<td><button id='t3' value='3' onclick='digitPress(this)'>3</button></td>
<td><button id='plus' value='+' onclick='commandPress(this)'>+</button></td>
</tr>
<tr>
<td><button id='t4' value='4' onclick='digitPress(this)'>4</button></td>
<td><button id='t5' value='5' onclick='digitPress(this)'>5</button></td>
<td><button id='t6' value='6' onclick='digitPress(this)'>6</button></td>
<td><button id='minus' value='-' onclick='commandPress(this)'>-</button></td>
</tr>
<tr>
<td><button id='t7' value='7' onclick='digitPress(this)'>7</button></td>
<td><button id='t8' value='8' onclick='digitPress(this)'>8</button></td>
<td><button id='t9' value='9' onclick='digitPress(this)'>9</button></td>
<td><button id='star' value='*' onclick='commandPress(this)'>*</button></td>
</tr>
<tr>
<td></td>
<td><button id='t0' value='0' onclick='digitPress(this)'>0</button></td>
<td><button id='t.' value='.' onclick='digitPress(this)'>.</button></td>
<td><button id='division' value='/'onclick='commandPress(this)'>/</button></td>
</tr>
</table>
</body>
</html>