# BigFloat type

**URL:** <https://discourse.julialang.org/t/bigfloat-type/114782>\
**Category:** General Usage\
**Tags:** bigfloat\
**Created:** [May 27, 2024, 1:42pm UTC](https://discourse.julialang.org/t/bigfloat-type/114782 "2024-05-27T13:42:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Denis\_Dardenne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/denis_dardenne/32/207669_2.png) [@Denis\_Dardenne](https://discourse.julialang.org/u/Denis_Dardenne)\
**Post date:** [May 27, 2024, 1:42pm UTC](https://discourse.julialang.org/t/bigfloat-type/114782/1 "2024-05-27T13:42:07Z")

</div>

Hello,  
I have a variable of this type:

 ![Capture d'écran 2024-05-27 153323](https://global.discourse-cdn.com/julialang/original/3X/f/0/f0dd55529ec967b842f7dd03a5f2f23cf11970b5.png)  
and I would like tto ransform the format Float64 to BigFloat. How do that ?

The following command doesn’t work :  
BigFloat.(MyVar)  
convert(BigFloat,MyVar)

May be defining the BigFloat as default format ? (I am not found this way)

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [May 27, 2024, 3:22pm UTC](https://discourse.julialang.org/t/bigfloat-type/114782/2 "2024-05-27T15:22:11Z")

</div>

> [@Denis\_Dardenne](#):
>
> and I would like to transform the format Float64 to BigFloat. How do that ?

`big.(MyVar)`, maybe?

In general, if you want to use `BigFloat`, then you should change the _inputs_ to your function, e.g. pass a `BigFloat` for the input when you call ForwardDiff.jl (which is what I presume you are using). If you don’t use `BigFloat` all the way through, you will generally be limited by the accuracy of the least-precise step of the computation.

The ideal is to write your functions so that they always compute in the precision of their inputs, so that you can pass in whatever precision you want (`Float64`, `Float32`, `BigFloat`) later and they will do the right thing. This takes a little practice to do properly, with the help of Julia’s type-promotion and introspection machinery, but if you post a specific example of a short function people can give you some tips on how to make it precision-generic.

PS. Don’t post screenshots of code. Post quoted code, and post minimal _runnable_ snippets to make it easier for other people to help you. Read [Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757)

---

<div class="post-metadata">

**Author:** ![Denis\_Dardenne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/denis_dardenne/32/207669_2.png) [@Denis\_Dardenne](https://discourse.julialang.org/u/Denis_Dardenne)\
**Post date:** [May 29, 2024, 5:42pm UTC](https://discourse.julialang.org/t/bigfloat-type/114782/3 "2024-05-29T17:42:01Z")

</div>

Thank you, using as input a BigFloat instead of Float format works.

---

<div class="post-metadata">

**Author:** ![RamonaMraz](https://avatars.discourse-cdn.com/v4/letter/r/a698b9/32.png) [@RamonaMraz](https://discourse.julialang.org/u/RamonaMraz)\
**Post date:** [June 20, 2024, 1:09pm UTC](https://discourse.julialang.org/t/bigfloat-type/114782/4 "2024-06-20T13:09:11Z")

</div>

> [@stevengj](#):
>
> > [@Denis\_Dardenne](#):
> >
> > and I would like to transform the format Float64 to BigFloat. How do that ?
> 
> `big.(MyVar)`, maybe?
> 
> In general, if you want to use `BigFloat`, then you should change the _inputs_ to your function, e.g. pass a `BigFloat` for the input when you call [ForwardDiff.jl] (which is what I presume you are using). If you don’t use `BigFloat` all the way through, you will generally be limited by the accuracy of the least-precise step of the computation.
> 
> > ****
> >
> > To convert `MyVar` from `Float64` to `BigFloat` in Julia, use `MyBigFloat = BigFloat(MyVar)`. This constructor explicitly converts the variable type, ensuring compatibility with `BigFloat` operations. When I needed help with a difficult research paper, I turned to [https://canadianwritings.com/](https://canadianwritings.com/) The service was fantastic from start to finish. The writer provided a well-crafted paper that was thoroughly researched and clearly written. The customer support team was very helpful and responsive. I’m very satisfied with the service and will use them again.
> 
> The ideal is to write your functions so that they always compute in the precision of their inputs, so that you can pass in whatever precision you want (`Float64`, `Float32`, `BigFloat`) later and they will do the right thing. This takes a little practice to do properly, with the help of Julia’s type-promotion and introspection machinery, but if you post a specific example of a short function people can give you some tips on how to make it precision-generic.
> 
> PS. Don’t post screenshots of code. Post quoted code, and post minimal _runnable_ snippets to make it easier for other people to help you. Read [Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757)

Thanks for helping me out. You made my day 🙂
