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

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

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

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,873 questions

51,797 answers

573 users

How to extract the int part and the decimal part from float number in JavaScript

2 Answers

0 votes
var f = 376.287152; 
 
var s = f.toString();

var point_pos = s.indexOf('.');

var int_part = s.substring(0, point_pos);

var float_part = s.substring(point_pos + 1, s.length);
 
document.write(int_part + "<br />"); 
document.write(float_part + "<br />");    


  
   
/*
run:
    
376
287152
       
*/

 



answered Aug 31, 2019 by avibootz
0 votes
var f = 231.687612;
  
var int_part = Math.floor(f); 
var float_part = f - int_part;
      
document.write(int_part + "<br />");
document.write(float_part + "<br />");


   
/*
run:
    
231
0.6876120000000014
       
*/

 



answered Aug 31, 2019 by avibootz
...