I am new to making websites. I am making one to convert grams of sugar into no of teaspoons. I am not able to understand how to limit the decimal points in the output.
<script type="text/javascript">
function calcTS() {
var g=document.getElementById('wt').value;
var ts=document.getElementById('Tspoon').value;
document.getElementById('Tspoon').value = g/4.2;
}
function calcG() {
var g=document.getElementById('wt').value;
var ts=document.getElementById('Tspoon').value;
document.getElementById('wt').value= ts*4.20;
}
This is the output I am getting: 1 gram of sugar = 0.23809523809523808 teaspoons.
The output that I want: 1 gram of sugar = 0.2 teaspoons.