Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Disclosure: My content contains affiliate links.

43,181 questions

56,073 answers

573 users

How to get the number of digits after the decimal point in JavaScript

1 Answer

0 votes
function totalDigitsAfterDecimalPoint(num) {
    if (Number.isInteger(num)) {
    	return 0;
  	}

  	return num.toString().split('.')[1].length;
}

 
console.log(totalDigitsAfterDecimalPoint(3.14)); 
console.log(totalDigitsAfterDecimalPoint(48.0)); 
console.log(totalDigitsAfterDecimalPoint(-8.936)); 
console.log(totalDigitsAfterDecimalPoint(746.6)); 
console.log(totalDigitsAfterDecimalPoint(17264));   
   
   
   
   
/*
run:
   
2
0
3
1
0
   
*/

 



answered Jun 18, 2022 by avibootz
...