# \#printf

**URL:** https://discourse.julialang.org/tag/printf/1515.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [Avoid \`-\` in \`@sprintf("%.1f", -0.001)\`](https://discourse.julialang.org/t/avoid-in-sprintf-1f-0-001/137334)

<div class="topic-metadata">

**Author:** [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Replies:** 4\
**Last updated:** [May 29, 2026, 8:00pm UTC](https://discourse.julialang.org/t/avoid-in-sprintf-1f-0-001/137334 "2026-05-29T20:00:44Z")

</div>

The title says it all, but generally I want to avoid a negative number that is rounded to all-zeros by printf to have a -. julia\> using Printf julia\> @sprintf("%.1f", -0.001) "-0.0" ▶ see a truly horrid solution here

---

## [On formatting the display of integer arrays](https://discourse.julialang.org/t/on-formatting-the-display-of-integer-arrays/132023)

<div class="topic-metadata">

**Author:** [@rcomm](https://discourse.julialang.org/u/rcomm)\
**Replies:** 6\
**Last updated:** [September 1, 2025, 5:48pm UTC](https://discourse.julialang.org/t/on-formatting-the-display-of-integer-arrays/132023 "2025-09-01T17:48:14Z")

</div>

I do combinatorial work which generates arrays containing small integers. Some arrays are large, so to reduce memory footprint all calculations are done in UInt8. Part of the analysis is to visually scan displays of se…

---

## [How to use protected characters in a string (e.g. percent in printf)](https://discourse.julialang.org/t/how-to-use-protected-characters-in-a-string-e-g-percent-in-printf/67239)

<div class="topic-metadata">

**Author:** [@hdcpereira](https://discourse.julialang.org/u/hdcpereira)\
**Replies:** 1\
**Last updated:** [August 28, 2021, 6:25pm UTC](https://discourse.julialang.org/t/how-to-use-protected-characters-in-a-string-e-g-percent-in-printf/67239 "2021-08-28T18:25:41Z")

</div>

Hello there. How do I use these protected characters when writing a string? @printf "this code has failed in %.2f" fail\_percentage I would like the output to be this code has failed in 10.00% but when I use the % sy…

---

## [Print vs @printf](https://discourse.julialang.org/t/print-vs-printf/121272)

<div class="topic-metadata">

**Author:** [@hack3rcon](https://discourse.julialang.org/u/hack3rcon)\
**Replies:** 6\
**Last updated:** [October 26, 2024, 7:51am UTC](https://discourse.julialang.org/t/print-vs-printf/121272 "2024-10-26T07:51:40Z")

</div>

Hello, Is it possible to write the following program using print, round and digits instead of using @printf? using Printf # needed in order to use @printf function tickets() print("Price of reserved ticket? ") rP…

---

## [ArgumentError: First argument to \`@sprintf\` must be a format string](https://discourse.julialang.org/t/argumenterror-first-argument-to-sprintf-must-be-a-format-string/113697)

<div class="topic-metadata">

**Author:** [@WuSiren](https://discourse.julialang.org/u/WuSiren)\
**Replies:** 4\
**Last updated:** [May 1, 2024, 3:26pm UTC](https://discourse.julialang.org/t/argumenterror-first-argument-to-sprintf-must-be-a-format-string/113697 "2024-05-01T15:26:30Z")

</div>

julia\> using Printf julia\> @sprintf("%.2f", 3.14159) "3.14" julia\> @sprintf("%."\*"3"\*"f", 3.14159) ERROR: ArgumentError: First argument to \`@sprintf\` must be a format string. julia\> format\_str = "%.2f" "%.2f" julia\> …

---

## [How to print similar tabular process output?](https://discourse.julialang.org/t/how-to-print-similar-tabular-process-output/112928)

<div class="topic-metadata">

**Author:** [@WuSiren](https://discourse.julialang.org/u/WuSiren)\
**Replies:** 6\
**Last updated:** [April 16, 2024, 7:33am UTC](https://discourse.julialang.org/t/how-to-print-similar-tabular-process-output/112928 "2024-04-16T07:33:03Z")

</div>

How can I print a similar tabular process output in my code? (make them aligned) Nodes | B&B Tree | Objective Bounds | Dynamic Constraints | Work Proc. InQue…

---

## [Displaying numbers in Julia](https://discourse.julialang.org/t/displaying-numbers-in-julia/112807)

<div class="topic-metadata">

**Author:** [@Albert\_Zevelev](https://discourse.julialang.org/u/Albert_Zevelev)\
**Replies:** 15\
**Last updated:** [April 11, 2024, 11:04pm UTC](https://discourse.julialang.org/t/displaying-numbers-in-julia/112807 "2024-04-11T23:04:27Z")

</div>

I want to make a very simple calculation: julia\> 6500 \* ( (1.10)^58 ) 1.6356451710902702e6 But, the format I’m hoping to for is 1,635,645.17 or 1635645.17. I spent 10 minutes searching the internet & Julia built in h…

---

## [How to use @sprintf with "parametric" format string?](https://discourse.julialang.org/t/how-to-use-sprintf-with-parametric-format-string/70364)

<div class="topic-metadata">

**Author:** [@ryszard314159](https://discourse.julialang.org/u/ryszard314159)\
**Replies:** 5\
**Last updated:** [April 1, 2024, 9:01pm UTC](https://discourse.julialang.org/t/how-to-use-sprintf-with-parametric-format-string/70364 "2024-04-01T21:01:33Z")

</div>

Is there a way to use @sprintf with “parametric” format string? or it has to be hardcoded? This is an example: julia\> @sprintf(“test: %s”, “test”) “test: test” julia\> fmt = “test: %s”; @sprintf(fmt, “test”) ERROR: L…

---

## [@printf: significant digits in floating point representation](https://discourse.julialang.org/t/printf-significant-digits-in-floating-point-representation/29978)

<div class="topic-metadata">

**Author:** [@MatFi](https://discourse.julialang.org/u/MatFi)\
**Replies:** 12\
**Last updated:** [March 9, 2024, 8:58pm UTC](https://discourse.julialang.org/t/printf-significant-digits-in-floating-point-representation/29978 "2024-03-09T20:58:32Z")

</div>

hi i want tu use @sprintf to format a number to floating point representation with a fixed amount of significant digits how can I do that? The function shout act the following way: .000012340000 -\> 0.000012 .12340000…

---

## [@Printf with DecFP / Dec128](https://discourse.julialang.org/t/printf-with-decfp-dec128/108996)

<div class="topic-metadata">

**Author:** [@JonT](https://discourse.julialang.org/u/JonT)\
**Replies:** 2\
**Last updated:** [January 19, 2024, 10:08pm UTC](https://discourse.julialang.org/t/printf-with-decfp-dec128/108996 "2024-01-19T22:08:42Z")

</div>

I’m seeing two different outputs for Dec128 numbers println() vs @printf: (Julia v1.10.0 with DecFP v1.3.2) using Printf, Quadmath, DecFP C = log2(big(ℯ)) # \\euler \<tab\> to get symbol d = convert(Dec128, C) println("C …

---

## [Printf with variable format string](https://discourse.julialang.org/t/printf-with-variable-format-string/3805)

<div class="topic-metadata">

**Author:** [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Replies:** 14\
**Last updated:** [May 22, 2023, 9:04pm UTC](https://discourse.julialang.org/t/printf-with-variable-format-string/3805 "2023-05-22T21:04:55Z")

</div>

Due to @printf being a macro, it does not accept a format string that has been passed as a variable. myvec = randn(4) n = length(myvec) outstring = "Beginning of string with some numbers: " for i = 1:n outstring = o…
