Decimal limit jQuery


This question already has an answer here:



function update($ele) {
    var n = Number($ele.find('.numerator')[0].value);
    var d = Number($ele.find('.denominator')[0].value);
    /* this works but is slightly more verbose (and maybe a bit slower) */
    var val = (n / d * 100);
    $ele.find('.result').text(( isNaN(val) || ! isFinite(val) ) ? '' : val.toFixed(2));
    /* This might be faster, and also make everything a bit more succinct * /
    var val = d !== 0 ? n / d * 100 : NaN;
    $ele.find('.result').text(isNaN(val) ? '' : val.toFixed(2));
    /* */

Need Your Help

Play sound at an exact moment

windows audio naudio low-latency

I want to play a sound sample (about 2 minute long) and record keystrokes while the sample is playing. I need to know the exact time a key was pressed relative to the play start time, with a resolu...

MongoDB return two object for every group

mongodb mongodb-query aggregation-framework

I want to get two objects $first and $last after grouping. Is it possible?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.