# Converting a double number into a string (not printing!)

**URL:** https://discourse.julialang.org/t/converting-a-double-number-into-a-string-not-printing/65492
**Category:** New to Julia
**Created:** [July 29, 2021, 12:09pm UTC](https://discourse.julialang.org/t/converting-a-double-number-into-a-string-not-printing/65492 "2021-07-29T12:09:44Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![julio.ca2020](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@julio.ca2020](https://discourse.julialang.org/u/julio.ca2020)
#### Post date: [July 29, 2021, 12:09pm UTC](https://discourse.julialang.org/t/converting-a-double-number-into-a-string-not-printing/65492/1 "2021-07-29T12:09:44Z")

</div>

I am trying to get a string with a number (double) formatted with 2 decimals… If i use interpolation I get the following  
A = 3.14256789  
c = “The letter is $A”  
c is then “The letter is 3.14256789”…

What I am looking for is “The letter is 3.14”.

If I use the printf package I can print what I am looking for, but not able to store it as variable.  
@printf(“the letter is %.2f”, A)

Any solution to this?

---

<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: [July 29, 2021, 12:12pm UTC](https://discourse.julialang.org/t/converting-a-double-number-into-a-string-not-printing/65492/2 "2021-07-29T12:12:42Z")

</div>

I usually just use `round(A, digits = 2)` for this (or `round(A, RoundDown, digits = 2)` if you want to cut off the remaning digits rather than round up if the third digit is \>= 0.5)

---

<div class="post-metadata">

### Author: ![julio.ca2020](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@julio.ca2020](https://discourse.julialang.org/u/julio.ca2020)
#### Post date: [July 29, 2021, 12:23pm UTC](https://discourse.julialang.org/t/converting-a-double-number-into-a-string-not-printing/65492/3 "2021-07-29T12:23:33Z")

</div>

> [@nilshg](#):
>
> round(A, digits = 2)

Thanks … Its a workaround… But if if you want @printf(“the letter is %3.f2”, A)… how would you do it?

---

<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: [July 29, 2021, 12:28pm UTC](https://discourse.julialang.org/t/converting-a-double-number-into-a-string-not-printing/65492/4 "2021-07-29T12:28:06Z")

</div>

Use `@sprintf`:

```julia
julia> x = @sprintf("the letter is %3.f2", A)
"the letter is 32"

julia> x
"the letter is 32"

```

---

<div class="post-metadata">

### Author: ![julio.ca2020](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@julio.ca2020](https://discourse.julialang.org/u/julio.ca2020)
#### Post date: [July 29, 2021, 12:37pm UTC](https://discourse.julialang.org/t/converting-a-double-number-into-a-string-not-printing/65492/5 "2021-07-29T12:37:11Z")

</div>

Thanks… That’s what I was looking for
