Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

check if number is decimal or integer js

// check if number inserted in input is decimal or integer
// if integer, return the integer value,
// else set fixed limit for decimal value.
// e.g. 15.347394 => 15.347

function check(element) {
  if (Number.isInteger(element)) {
    return element;
  }
  return element.toFixed(3);
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #check #number #decimal #integer #js
ADD COMMENT
Topic
Name
1+3 =