Jump to content

Convert a Number with a comma to a point?


Go to solution Solved by Malkey,

Recommended Posts

Nevermind I sussed it. I used StringReplace()

Local $sString = StringReplace("1,62918.", ",", ".")
Local $iReplacements = @extended
MsgBox($MB_SYSTEMMODAL, "", $iReplacements & " replacements were made and the new string is:" & @CRLF & @CRLF & $sString)

I did spend about an hour prior to posting this trying to figure this out. Sorry for wasting your time.

Link to comment
Share on other sites

  • Solution

Using StringReplace() is fine to blanket convert all commas.
In case there are any commas in the string that don't need converting, here is a conditional converting method.

Local $sOrigString = 'When a comma is between digits, replace with a point e.g. StringReplace("1,62918,", ",", ".")'

Local $sString = StringRegExpReplace($sOrigString, "(?<=\d),(?=\d)", ".")
Local $iReplacements = @extended

MsgBox(4096, "", $iReplacements & " replacement" & _ ; $MB_SYSTEMMODAL is 4096
        ($iReplacements = 1 ? " was" : "s were") & _ ; Allow for plural or singular grammatically.
        " made and the new string is:" & _
        @CRLF & @CRLF & $sString)

; The RE Pattern:-
; "(?<=\d)," - (Lookbehind assertions) Match an occurrence of a comma, ",", that is preceded by a digit, "\d", but does not include the digit in the match; and,
; ",(?=\d)"  - (Lookahead assertions) Matches a comma followed by a digit, "\d", but does not include the digit in the match.
; So, to match a particular comma to convert, there must be a digit on either side of the comma.

; Returns :-
; 1 replacement was made and the new string is:
;
; When a comma is between digits, replace with a point e.g. StringReplace("1.62918,", ",", ".")
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ : Replacement : Comma converted to point.

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...