반응형
Remove last 3 characters of string or number in javascript
I'm trying to remove last 3 zeroes 1437203995000
How do i this in javascript. Im generating the numbers from new date() function
Here is an approach using str.slice(0, -n)
. Where n is the number of characters you want to truncate.
var str = 1437203995000;
str = str.toString();
console.log("Original data: ",str);
str = str.slice(0, -3);
str = parseInt(str);
console.log("After truncate: ",str);
Remove last 3 characters of a string
var str = '1437203995000';
str = str.substring(0, str.length-3);
// '1437203995'
Remove last 3 digits of a number
var a = 1437203995000;
a = (a-(a%1000))/1000;
// a = 1437203995
ReferenceURL : https://stackoverflow.com/questions/31489413/remove-last-3-characters-of-string-or-number-in-javascript
반응형
'Programing' 카테고리의 다른 글
Maven plugins can not be found in IntelliJ (0) | 2020.12.24 |
---|---|
How can I expand a child div to 100% screen width if the container div is smaller? (0) | 2020.12.24 |
Why would one mark local variables and method parameters as “final” in Java? (0) | 2020.12.24 |
ASP.NET MVC ViewResult vs PartialViewResult (0) | 2020.12.24 |
Extend a java class from one file in another java file (0) | 2020.12.24 |