# Parsing Float64 as Float64

**URL:** https://discourse.julialang.org/t/parsing-float64-as-float64/83301
**Category:** General Usage
**Created:** [June 24, 2022, 10:51am UTC](https://discourse.julialang.org/t/parsing-float64-as-float64/83301 "2022-06-24T10:51:12Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![ccookeopen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ccookeopen/32/37417_2.png) [@ccookeopen](https://discourse.julialang.org/u/ccookeopen)
#### Post date: [June 24, 2022, 10:51am UTC](https://discourse.julialang.org/t/parsing-float64-as-float64/83301/1 "2022-06-24T10:51:13Z")

</div>

Hi,

Reading data from various excel files, sometimes it is correctly formatted as a Float, sometimes it is interpreted as a string.

If I account for the second case, I must use parse(Float64, input). Using this code in the first case gives the error

no method matching parse(::Type{Float64}, ::Float64)

It seems odd that the parser cannot interpret a Float64 number as… a Float64 number.

The workaround is to tediously reproduce code for both instances, whereas accepting Float64 as an argument means the same code would work either way.

C

---

<div class="post-metadata">

### Author: ![jedforrest](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jedforrest/32/37502_2.png) [@jedforrest](https://discourse.julialang.org/u/jedforrest)
#### Post date: [June 24, 2022, 11:23am UTC](https://discourse.julialang.org/t/parsing-float64-as-float64/83301/2 "2022-06-24T11:23:48Z")

</div>

It looks like `parse` is only for converting strings into numbers, and doesn’t work on any other type (for that, you could use `convert` instead).

This is a little hacky, but you could try turning everything into a string first?

```julia
parse(Float64, string(x))

```

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [June 24, 2022, 11:23am UTC](https://discourse.julialang.org/t/parsing-float64-as-float64/83301/3 "2022-06-24T11:23:59Z")

</div>

That’s probably this issue:

[https://github.com/felipenoris/XLSX.jl/issues/192](https://github.com/felipenoris/XLSX.jl/issues/192)

You can do `x -> x isa Number ? x : parse(Float64, x)`

---

<div class="post-metadata">

### Author: ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)
#### Post date: [June 24, 2022, 11:59am UTC](https://discourse.julialang.org/t/parsing-float64-as-float64/83301/4 "2022-06-24T11:59:13Z")

</div>

I think it’s good that parsing is restricted to strings, but you can make your own parsing function that is more lenient. This one always accepts a value of type T as is if we’re parsing that T. One could think of even more lenient variants:

```julia
sloppy_parse(::Type{T}, x::T) where T = x
sloppy_parse(T, x) = parse(T, x)

```
