# Convert a Number with a comma to a point?

Go to solution Solved by Malkey,

## Recommended Posts

Hello,

Would someone be able to help me with something. I have a number say 1,62918 which has a comma but I need it as 1.62918 with a point, how do I go about doing this?

##### Share on other sites

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.

##### 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.```

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...