Answers for "adding decimals result in long javascript"

11

javascript show 2 decimal places

var myNumber=12.2345;
var myNumberWithTwoDecimalPlaces=parseFloat(myNumber).toFixed(2); //12.23
Posted by: Guest on July-31-2019
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

Code answers related to "adding decimals result in long javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language