Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript - get milliseconds from float seconds

Tags:

javascript

I got a string that represents seconds (e.g value is "14.76580"). I want to set a new variable that has the value of the decimal portion (milliseconds) of that string ( e.g x = 76580 ) and I'm not sure what's the best way to do that. May you help please ?

like image 461
Lironess Avatar asked Dec 15 '22 10:12

Lironess


1 Answers

You can use this function to calculate the ms portion from a time (works on strings too):

function getMilliSeconds(num)
{
    return (num % 1) * 1000;
}

getMilliSeconds(1.123); // 123
getMilliSeconds(14.76580); // 765.8000000000005
like image 160
Ja͢ck Avatar answered Jan 17 '23 07:01

Ja͢ck