# How to convert comma-seperated number to number?

**URL:** <https://discourse.julialang.org/t/how-to-convert-comma-seperated-number-to-number/76906>\
**Category:** General Usage\
**Tags:** dataframes, excel\
**Created:** [February 22, 2022, 1:12pm UTC](https://discourse.julialang.org/t/how-to-convert-comma-seperated-number-to-number/76906 "2022-02-22T13:12:19Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![yummy527](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yummy527/32/34025_2.png) [@yummy527](https://discourse.julialang.org/u/yummy527)\
**Post date:** [February 22, 2022, 1:12pm UTC](https://discourse.julialang.org/t/how-to-convert-comma-seperated-number-to-number/76906/1 "2022-02-22T13:12:19Z")

</div>

Data are read from excel xls file in which some numbers are stored as text and comma-seperated.  
excel screenshot:  
 ![Screenshot_20220222_210423](https://global.discourse-cdn.com/julialang/original/3X/0/e/0e3cbe6bc575486088f1188f720f2a487f075431.png)

Dataframe sreenshot (read using ExcelFiles.jl):  
 ![Screenshot_20220222_210019](https://global.discourse-cdn.com/julialang/original/3X/3/0/30ccc70e5ceea448ea7d444c11a2536d69d8943d.png)

I have tried function _tryparse_ or _parse_, but it does not work as expected. Failed example in short here:

```julia
tryparse(Float64, "1,000")

```

The question is: how to convert these comma-seperated texted numbers to normal numbers in Julia?

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [February 22, 2022, 1:20pm UTC](https://discourse.julialang.org/t/how-to-convert-comma-seperated-number-to-number/76906/2 "2022-02-22T13:20:40Z")

</div>

```julia
julia> parse(Float64, replace("1,000", "," => "."))
1.0

```

---

<div class="post-metadata">

**Author:** ![yummy527](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yummy527/32/34025_2.png) [@yummy527](https://discourse.julialang.org/u/yummy527)\
**Post date:** [February 22, 2022, 1:27pm UTC](https://discourse.julialang.org/t/how-to-convert-comma-seperated-number-to-number/76906/3 "2022-02-22T13:27:09Z")

</div>

Thanks. It would work.  
However, given the background of dealing with DataFrame read from Excel, I am not sure if there is any conventional trick to do this conversion?

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [February 22, 2022, 1:37pm UTC](https://discourse.julialang.org/t/how-to-convert-comma-seperated-number-to-number/76906/4 "2022-02-22T13:37:05Z")

</div>

Well, you could create a feature request for [https://github.com/queryverse/ExcelReaders.jl](https://github.com/queryverse/ExcelReaders.jl) to do this conversion using a keyword argument…

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [February 22, 2022, 1:39pm UTC](https://discourse.julialang.org/t/how-to-convert-comma-seperated-number-to-number/76906/5 "2022-02-22T13:39:38Z")

</div>

There is a reason you are not saving the file as CSV, and reading it to a DataFrame with `CSV.jl` and `DataFrames.jl`?

Also, are you sure the comma is not being used to separate thousands? The solution given consider it is separating the fractional part, but considering the magnitude of the values (and the fact it is always three digits after the comma) involved it seems like it using the comma to separate thousands not the fractional part.

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [February 22, 2022, 2:32pm UTC](https://discourse.julialang.org/t/how-to-convert-comma-seperated-number-to-number/76906/6 "2022-02-22T14:32:52Z")

</div>

In case the comma is used to separate thousands you need to write

```julia
parse(Float64, replace("1,000", "," => "")) instead...

```

---

<div class="post-metadata">

**Author:** ![yummy527](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yummy527/32/34025_2.png) [@yummy527](https://discourse.julialang.org/u/yummy527)\
**Post date:** [February 23, 2022, 1:05am UTC](https://discourse.julialang.org/t/how-to-convert-comma-seperated-number-to-number/76906/7 "2022-02-23T01:05:20Z")

</div>

We have a batch of legacy xls files with several sheets.

---

<div class="post-metadata">

**Author:** ![yummy527](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yummy527/32/34025_2.png) [@yummy527](https://discourse.julialang.org/u/yummy527)\
**Post date:** [February 23, 2022, 3:47am UTC](https://discourse.julialang.org/t/how-to-convert-comma-seperated-number-to-number/76906/8 "2022-02-23T03:47:59Z")

</div>

Thanks. Replace and parse works!
