# How to Convert Computation Result in Julia in pi terms?

**URL:** https://discourse.julialang.org/t/how-to-convert-computation-result-in-julia-in-pi-terms/92700
**Category:** General Usage
**Tags:** question
**Created:** [January 9, 2023, 8:24am UTC](https://discourse.julialang.org/t/how-to-convert-computation-result-in-julia-in-pi-terms/92700 "2023-01-09T08:24:02Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)
#### Post date: [January 9, 2023, 8:24am UTC](https://discourse.julialang.org/t/how-to-convert-computation-result-in-julia-in-pi-terms/92700/1 "2023-01-09T08:24:02Z")

</div>

Hi all,

I want to show the result of my computation in pi terms, instead of float with lots of decimal numbers. Is it possible?

Here is my code:

```julia
using Plots, LaTeXStrings; gr()
#=
# To plot a curve starting at (0, 0) 
θ = 0:0.1:4.1π
x = θ .- sin.(θ)
y = 1 .- cos.(θ)
plot(x, y, xlims=(0,15), ylims=(0,4),
	label=L"(x,y) = (\theta - \sin \ t , 1 - \cos \ t)",
	framestyle=:zerolines, aspect_ratio=:equal)
=#

println("t \t x \t \t y")
for N in 0:pi/2:4*pi
    x1 = (N) - sin.(N) 
    y1 = 1 - cos.(N) 
    println("$N \t $x1 \t $y1")
end

```

I want it like the left table:

 ![Capture d’écran_2023-01-09_15-21-45](https://global.discourse-cdn.com/julialang/original/3X/b/b/bb37ca8f5221292335a994d360eb0a7a40ecccfa.png)

---

<div class="post-metadata">

### Author: ![Dan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan/32/42581_2.png) [@Dan](https://discourse.julialang.org/u/Dan)
#### Post date: [January 9, 2023, 12:21pm UTC](https://discourse.julialang.org/t/how-to-convert-computation-result-in-julia-in-pi-terms/92700/2 "2023-01-09T12:21:03Z")

</div>

Here is an idea using PrettyTables package:

```julia
julia> using PrettyTables

julia> println(pretty_table(String, 
  vcat([[string(t)*"π" t*π-sinpi(t) 1-cospi(t)] for t in 0:0.5:4]...); 
  header=["t", "x(t)", "y(t)"]))
┌──────┬──────────┬──────┐
│ t │ x(t) │ y(t) │
├──────┼──────────┼──────┤
│ 0.0π │ 0.0 │ 0.0 │
│ 0.5π │ 0.570796 │ 1.0 │
│ 1.0π │ 3.14159 │ 2.0 │
│ 1.5π │ 5.71239 │ 1.0 │
│ 2.0π │ 6.28319 │ 0.0 │
│ 2.5π │ 6.85398 │ 1.0 │
│ 3.0π │ 9.42478 │ 2.0 │
│ 3.5π │ 11.9956 │ 1.0 │
│ 4.0π │ 12.5664 │ 0.0 │
└──────┴──────────┴──────┘

```

UPDATE: corected according to Oscar\_Smith suggestion to use `sinpi`, `cospi`

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [January 9, 2023, 12:37pm UTC](https://discourse.julialang.org/t/how-to-convert-computation-result-in-julia-in-pi-terms/92700/3 "2023-01-09T12:37:23Z")

</div>

For rational fraction display take a look at [this post](https://discourse.julialang.org/t/plot-with-x-axis-in-radians-with-ticks-at-multiples-of-pi/65325/3).

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [January 9, 2023, 12:50pm UTC](https://discourse.julialang.org/t/how-to-convert-computation-result-in-julia-in-pi-terms/92700/4 "2023-01-09T12:50:57Z")

</div>

note that we have `sinpi` and `cospi`

---

<div class="post-metadata">

### Author: ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)
#### Post date: [January 10, 2023, 7:22am UTC](https://discourse.julialang.org/t/how-to-convert-computation-result-in-julia-in-pi-terms/92700/5 "2023-01-10T07:22:35Z")

</div>

Thanks for the `PrettyTables` suggestion
