Q:

How can I add minus sign in jquery? 

My html code :-
<input type="text" id="test">
<span class="display"></span>

My jquery code :
$("#test").keyup(function(e){
  $('span.display').text(formatCurrency($(this).val()));
  this.value = this.value.replace(/[^0-9\.]/g,'');
});

Demo and full code is like this : https://jsfiddle.net/oscar11/nbLbb037/
I want the input text can enter this : -10000000
And the result who displayed in class display is : -10.000.000
How can I add minus (-) sign? 

A:

Need to change code like below:-
output = output.reverse();
if(output[1] == '.'){ 
   output.splice(1, 1);
   formatted = output.join("");
}else{
   formatted = output.join("");
}

And every thing will be fine. 
Example:-

$("#test").keyup(function(e){
  
  $('span.display').text(formatCurrency($(this).val()));
  this.value = this.value.replace(/[^0-9\.-]/g,'');
});


// format currency on pagu and revisi
var formatCurrency = function(num){
    var str = num.toString().replace("$", ""), parts = false, output = [], i = 1, formatted = null;
    if(str.indexOf(",") > 0) {
        parts = str.split(",");
        str = parts[0];
    }
    str = str.split("").reverse();
    for(var j = 0, len = str.length; j < len; j++) {
        if(str[j] ! = ".") { 
            output.push(str[j]);
            if(i%3 == 0 && j < (len - 1)) {
                output.push("."); 
            }
            i++;
        }
    }
     output = output.reverse();
     if(output[1] == '.'){ 
        output.splice(1, 1);
        formatted = output.join("");
     }else{
        formatted = output.join("");
     }
    return(formatted + ((parts) ? ","  + parts[1].substr(0, 1) : ""));
};
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="test">
<span class="display"></span>

