I'm trying to remove last 3 zeroes 1437203995000
我正在尝试删除最后3个零1437203995000
How do i this in javascript. Im generating the numbers from new date() function
我在javascript中怎么做?我从新的date()函数生成数字
2 个解决方案
#1
38
Here is an approach using str.slice(0, -n)
. Where n is the number of characters you want to truncate.
这是一种使用str.slice(0,-n)的方法。其中n是要截断的字符数。
var str = 1437203995000;
str = str.toString();
console.log("Original data: ",str);
str = str.slice(0, -3);
str = parseInt(str);
console.log("After truncate: ",str);
#2
14
Remove last 3 characters of a string
删除字符串的最后3个字符
var str = '1437203995000';
str = str.substring(0, str.length-3);
// '1437203995'
Remove last 3 digits of a number
删除数字的后3位数字
var a = 1437203995000;
a = (a-(a%1000))/1000;
// a = 1437203995
#1
38
Here is an approach using str.slice(0, -n)
. Where n is the number of characters you want to truncate.
这是一种使用str.slice(0,-n)的方法。其中n是要截断的字符数。
var str = 1437203995000;
str = str.toString();
console.log("Original data: ",str);
str = str.slice(0, -3);
str = parseInt(str);
console.log("After truncate: ",str);
#2
14
Remove last 3 characters of a string
删除字符串的最后3个字符
var str = '1437203995000';
str = str.substring(0, str.length-3);
// '1437203995'
Remove last 3 digits of a number
删除数字的后3位数字
var a = 1437203995000;
a = (a-(a%1000))/1000;
// a = 1437203995