JSFiddle - React, Tailwind, and code Playground
by sabithpocker
HTML
<form action="#">
Enter the no: <input type="text" name="decimal" id="decimal"/><br />
<label id="error"></label>
</form>
CSS
form{
border:1px solid #444;
background-color:#eee;
margin:20px;
padding:10px;
}
#error{
margin:5px;
background-color:#bc0000;
color:#FFFFFF;
display:block;
}
JavaScript
$(document).ready(function(){
$('input#decimal').blur(function(){
var num = parseFloat($(this).val());
var cleanNum = num.toFixed(2);
$(this).val(cleanNum);
if(num/cleanNum < 1){
$('#error').text('Please enter only 2 decimal places, we have truncated extra points');
}
});
});