I need it to look like this: -20.00
I need it to look like this: -20.00
Just concatenate the - (minus) sign to the returned value
$('input').change(function(){
var input = "-" + ($('#numInput').val());
console.log(input);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><inputid="numInput">
To use in mathematical calculations requires turning the comma into a point
$('input').keyup(function(){
var input = "-" + $($(this)).val().replace(',','.');
var result = ((100+parseFloat(input)).toFixed(2));
console.log(result);
var resultVirgula = result.replace('.',',');
console.log(resultVirgula);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><inputid="numInput">
A very simple implementation for this problem:
$('#mask').keyup(function(){
if((this.value.search('-') == -1 && this.value.length > 0 )){
$(this).val('-' + this.value);
}
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><inputtype="text" id="mask" >Máscara