# Parsing Float32 literals

**URL:** <https://discourse.julialang.org/t/parsing-float32-literals/25204>\
**Category:** General Usage\
**Created:** [June 12, 2019, 7:27pm UTC](https://discourse.julialang.org/t/parsing-float32-literals/25204 "2019-06-12T19:27:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [June 12, 2019, 7:27pm UTC](https://discourse.julialang.org/t/parsing-float32-literals/25204/1 "2019-06-12T19:27:09Z")

</div>

This caught me by surprise:

```julia
julia> parse(Float32, "1.0f0")
ERROR: ArgumentError: cannot parse "1.0f0" as Float32

```

`Float32` seems special

```julia
julia> x = UInt8(1)
0x01

julia> parse(typeof(x), repr(x))
0x01

julia> x = UInt16(1)
0x0001

julia> parse(typeof(x), repr(x))
0x0001

ulia> x = Float64(1)
1.0

julia> parse(typeof(x), repr(x))
1.0

julia> x = Float32(1)
1.0f0

julia> parse(typeof(x), repr(x))
ERROR: ArgumentError: cannot parse "1.0f0" as Float32

```

`Float16` also fails, but that doesn’t have a proper literal representation:

```julia
julia> x = Float16(1)
Float16(1.0)

julia> parse(typeof(x), repr(x))
ERROR: ArgumentError: cannot parse "Float16(1.0)" as Float16

```

Is this intentional?

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [June 12, 2019, 7:52pm UTC](https://discourse.julialang.org/t/parsing-float32-literals/25204/2 "2019-06-12T19:52:18Z")

</div>

[https://github.com/JuliaLang/julia/issues/5690](https://github.com/JuliaLang/julia/issues/5690)

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [June 12, 2019, 8:16pm UTC](https://discourse.julialang.org/t/parsing-float32-literals/25204/3 "2019-06-12T20:16:36Z")

</div>

Oh, and oldie. But, if I understand Jeff’s comment, it seems like `parse` ought to work?

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [June 12, 2019, 8:19pm UTC](https://discourse.julialang.org/t/parsing-float32-literals/25204/4 "2019-06-12T20:19:12Z")

</div>

> [@DNF](#):
>
> it seems like `parse` ought to work?

It does:

```julia
julia> Meta.parse("1f0")
1.0f0

```
