[英]To remove the alphabets and special characters from the floating number?
I have below string in that i have to filter out alphabets and special characters and also i have to remove the dot which is appearing after the decimal point.我有下面的字符串,我必须过滤掉字母和特殊字符,而且我必须删除出现在小数点后的点。
var number = '1.25eretr6565....$#$%'
number.replace( /[^0-9.]/g, '' );
For the above am getting the result as "1.256565...."
对于上述情况,结果为
"1.256565...."
but the expected result is 1.256565
.但预期结果是
1.256565
。 Have to remove the dot which is appearing after the decimal point?必须删除小数点后出现的点吗?
You can try this:你可以试试这个:
number.replace(/[^0-9.]/g, '' ).split(".").filter(item => item !== "").map((item, index) => (index === 0)?item+'.' : item
).join('')
Happy to help乐意效劳
You Can try this:你可以试试这个:
function getNumberValueFromAlphanumeric(number) {
var numberValue = number.replace( /[^0-9.]/g, '' );
var valueArray = numberValue.split(".").filter(item => item !== "");
// extract first value
var firstValue = valueArray[0];
//remove first value from array
valueArray.shift()
//create second value
var secondValue = valueArray.join("");
var expectedValue = firstValue + "." + secondValue;
return expectedValue;
}
this works for all value that I can think of at this moment Happy to help这适用于我此刻能想到的所有价值 乐于提供帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.