简体   繁体   English

删除整数之间的空格 - JavaScript / ReactJS

[英]Removing white space between integers - JavaScript / ReactJS

I have a question .我有个问题 。 How can i remove white space between integers ?如何删除整数之间的空格? I want to keep my numbers as numbers and display them as one .我想将我的数字保留为数字并将它们显示为 1 。 I do not want to change my display to be a string .我不想将我的显示更改为 string 。 The current result that is displayed into my table is something like : 1 004 123 But on the end of the day i want to be : 1004123 .显示在我的表格中的当前结果类似于: 1 004 123但在一天结束时我想成为: 1004123 So how can achieve that ?那么如何才能做到这一点呢? Again i do not want to use myString.replace(/ /g,'') , str.trim() or toString() , i want to keep them as numbers .同样,我不想使用myString.replace(/ /g,'')str.trim()toString() ,我想将它们保留为数字。 Thank you .谢谢你 。

You will have to treat it as string, then you can parse it.您必须将其视为字符串,然后才能解析它。 eg例如

var stringNum = "1 004 123".toString().replace(/ /g,'');
var num = parseInt(stringNum);
console.log(num); //1004123

Double convert?双转换? From integer to string for deleting withe space and after from string to integer.从整数到字符串删除空格,然后从字符串到整数。 You can do this?你可以这样做?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM