开发者

Regex to get float from a string

Hay, i have a system basically tracks finances. In this application it has a "cost" field (which unfortunately is VARCHAR field). This field has various values entered like:

£90
£210 per day
开发者_StackOverflow中文版£50 per logo
Design - £180
£36 p/h
£1009.51

Is there any way i can convert these to floats? I tried just using (float) to juggle the type into a float, but it isn't working.


If it's always following a £ character, you can even make sure other numbers don't match:

£\s*\d+(?:\.\d+)?

Explanation

£          # GBP
\s*        # spaces, optional
\d+        # digits, required (at least one)
(?:        # non-capturing group 
  \.\d+    #   a literal dot, and more digits
)?         # end group, make optional


/(\d+[.]?\d*)/

Edited

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜