Jquery calculation not working properly
<p>I have a little piece of jQuery code which calculates the recipe ingredients as per given serving, but somewhere it's not working properly.</p>

<p>My code is like this:</p>

<pre><code>Serving: &lt;input type="text" name="serving" class="serving" value="5" /&gt; persons
&lt;input type="hidden" id="previousServing" value="5"/&gt;

        &lt;h3&gt;ingredients&lt;/h3&gt;
        &lt;ul class="ingredients"&gt;
        &lt;li class="ingredient"&gt;
        &lt;span class="amount"&gt;1&lt;/span&gt; cups
        &lt;span class="name"&gt;&lt;a href="http://www.mysite.com/ingredient/yogurt/"&gt;yogurt&lt;/a&gt;&lt;/span&gt;
        &lt;/li&gt;

        &lt;li class="ingredient"&gt;
        &lt;span class="amount"&gt;2&lt;/span&gt; tbsp
        &lt;span class="name"&gt;&lt;a href="http://www.mysite.com/ingredient/yogurt/"&gt;chillies&lt;/a&gt;&lt;/span&gt;
        &lt;/li&gt;

        &lt;li class="ingredient"&gt;
        &lt;span class="amount"&gt;3&lt;/span&gt; pieces
        &lt;span class="name"&gt;&lt;a href="http://www.mysite.com/ingredient/yogurt/"&gt;butter&lt;/a&gt;&lt;/span&gt;
        &lt;/li&gt;
        &lt;/ul&gt;



$(function() {
  $('.serving').bind('keyup', function(event) {
    var previousValue = parseFloat($("#previousServing").val());
    var newValue = parseFloat($(event.target).val());
    if (previousValue &amp;&amp; newValue) {
        $('.ingredient').each(function(index, elem) {
            var ingredientNow = $('.amount', elem);
            var oldIngredientAmount = ingredientNow.text();
            var newIngredientAmount = oldIngredientAmount * newValue / previousValue;
            ingredientNow.text(newIngredientAmount);
        });
        $('#previousServing').val(newValue);
    }
});
});
</code></pre>

<p><a href="http://jsfiddle.net/vansimke/tLWpr/" rel="nofollow">http://jsfiddle.net/vansimke/tLWpr/</a></p>

<p>issues:</p>

<ol>
<li>change the serving to 1.5 and it will give unlimited decimal places</li>
<li>set the serving back to original (5), decimals wont disappear</li>
</ol>

<p>Required: either no decimals or round to absolute two digit, i.e., 2.08 should be 2.00.</p>

<p>Thanks in anticipation.</p>
