As the title states I am trying to check if a value had greater than 3 decimal places. This is the first time that I have had to deal with angularjs and I am not certain how to check that. I have check if value is whole number, greater than 0, etc.. But I am uncertain on the decimal places. Here is a snippet of my whole number check. Any suggestions on how I could do the check for the decimals would be greatly appreciated. I am trying to show a error message if the user goes over 3 decimals places.
Whole number example:
(mySubmittedOrder && myQuantity % 1 ===0)
CodePudding user response:
var num1 = 1.123;
function decimalCount(num){
var numStr = String(num);
// String Contains Decimal
if (numStr.includes('.')) {
return numStr.split('.')[1].length;
};
// String Does Not Contain Decimal
return 0;
}
var decimalNumber = decimalCount(num1);
if(decimalNumber == 3){
console.log("3 decimals");
}else{
console.log("Not 3 decimals");
}
CodePudding user response:
jQuery :
$filter('number')(number, fractionSize)
or Angular:
<span id='number-default'>{{val | number}}</span><br>