I'd like to format numbers into the numbers next to them with k, lacs, crores in jQuery:
1000 to 1K
1500 to 1.5K
100000 to 1Lac
150000 to 1.5Lac
1000000 to 10Lac
10000000 to 1cr and so on !
<!DOCTYPE html>
<html>
<head>
<title>Number Differentiation</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(e){
$('#numbr').bind('keypress', function (e) {
return (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57) && e.which != 46) ? false : true;
});
$("#submitBut").click(function(e){
alert(numDifferentiation( $("#numbr").val()))
})
function numDifferentiation($val){
return $val;
}
})
</script>
</head>
<body>
<input id="numbr" type="text"/>
<button id="submitBut">Click</button>
</body>
</html>
This should do it:
function numDifferentiation(val) {
if(val >= 10000000) val = (val/10000000).toFixed(2) + ' Cr';
else if(val >= 100000) val = (val/100000).toFixed(2) + ' Lac';
else if(val >= 1000) val = (val/1000).toFixed(2) + ' K';
return val;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With