简体   繁体   English

只从字符串中获取数字

[英]Getting only digits out of a string

I have this string - "4,450.50 $". 我有这个字符串 - “4,450.50 $”。

I need just the numbers from this string. 我只需要这个字符串中的数字。 So in this example i would like to get the number - 4450.50 back. 所以在这个例子中我想得到的数字 - 4450.50。

How could I get it? 我怎么能得到它?

str = "4,450.50 $"
Float str.scan(/[\d.]/).join
# => 4450.5

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

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