Answers for "js set number of decimals"

14

js number 2 decimal places

(3.141596).toFixed(2);	// 3.14
Posted by: Guest on August-13-2020
1

how count decimals javascript

const num1 = 1.123456789;
const num2 = 123456789;
const decimalCount = num => {
   // Convert to String
   const numStr = String(num);
   // String Contains Decimal
   if (numStr.includes('.')) {
      return numStr.split('.')[1].length;
   };
   // String Does Not Contain Decimal
   return 0;
}
console.log(decimalCount(num1)) // 9
console.log(decimalCount(num2)) // 0
Posted by: Guest on August-23-2021
-1

javascript no decimal places

const removedDecimal = Math.trunc(decimal);
// returns 5
Posted by: Guest on September-22-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language