# @Printf with DecFP / Dec128

**URL:** https://discourse.julialang.org/t/printf-with-decfp-dec128/108996
**Category:** Numerics
**Tags:** question, numbers, printf
**Created:** [January 19, 2024, 4:34am UTC](https://discourse.julialang.org/t/printf-with-decfp-dec128/108996 "2024-01-19T04:34:22Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![JonT](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@JonT](https://discourse.julialang.org/u/JonT)
#### Post date: [January 19, 2024, 4:34am UTC](https://discourse.julialang.org/t/printf-with-decfp-dec128/108996/1 "2024-01-19T04:34:22Z")

</div>

I’m seeing two different outputs for Dec128 numbers println() vs @printf:  
(Julia v1.10.0 with DecFP v1.3.2)

```julia
using Printf, Quadmath, DecFP
C = log2(big(ℯ)) # \euler <tab> to get symbol
d = convert(Dec128, C)
println("C = ", C)
println("d = ", d)
@printf("d = %.36f\n", d)
@printf("d = %.36f\n", convert(BigFloat,d))

```

Gives output

```julia
C = 1.442695040888963407359924681001892137426645954152985934135449406931109219181187
d = 1.442695040888963407359924681001892
d = 1.442695040888963387004650940070860088
d = 1.442695040888963407359924681001892000

```

Should I be using a different modifier not %f for DecFP formats ?

---

<div class="post-metadata">

### Author: ![StevenSiew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensiew/32/218393_2.png) [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)
#### Post date: [January 19, 2024, 9:21pm UTC](https://discourse.julialang.org/t/printf-with-decfp-dec128/108996/2 "2024-01-19T21:21:10Z")

</div>

Dont use Printf  
Write your own output string function using

````julia
"""
    sigexp(x::DecFP.DecimalFloatingPoint)

Return `(sign, significand, exponent)` such that `x` is equal to `sign * significand * 10^exponent`.
Throws `DomainError` for infinite or `NaN` arguments.

# Examples
```jldoctest
julia> sigexp(Dec64(1.25))
(1, 125, -2)

````

“”"

```julia

```

---

<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: [January 19, 2024, 10:08pm UTC](https://discourse.julialang.org/t/printf-with-decfp-dec128/108996/3 "2024-01-19T22:08:42Z")

</div>

> [@StevenSiew](#):
>
> Dont use Printf

Printf is _supposed_ to work with DecFP — @jmkuhn implemented some methods specifically to get this working a few years back: [Fix printf formatting by jmkuhn · Pull Request #48 · JuliaMath/DecFP.jl · GitHub](https://github.com/JuliaMath/DecFP.jl/pull/48)

Not sure if it has bitrotted recently or … ? ~~Maybe file an issue.~~ I’ve filed an issue: [printf is converting to `Float64` · Issue #178 · JuliaMath/DecFP.jl · GitHub](https://github.com/JuliaMath/DecFP.jl/issues/178)

It looks like there’s an implicit conversion to `Float64` going on with `@printf` that didn’t used to be there:

```julia-auto
julia> using DecFP, Printf

julia> x = rand(Dec128)
0.6498353664629435612857337361220566

julia> println(x)
0.6498353664629435612857337361220566

julia> @printf("%.36f", x)
0.649835366462943597731793943239608780
julia> 

julia> @printf("%.36f\n", Float64(x)) # matches @printf("%.36f", x) !!
0.649835366462943597731793943239608780

```
