Displaying numbers in Julia

Albert_Zevelev
Wed, 10 Apr 2024 22:20:50 +0000
General Usage

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 help & couldn’t find an easy way to display something that seems so simple.

Please tell me I’m missing something obvious.

Summary of some proposed solutions:

julia> x = 6500 * ( (1.10)^58 );

julia> using Printf; @printf("%.2f", x)
1635645.17
julia> using Format; format(x; commas=true, precision=2)
"1,635,645.17"

I’m surprised round() doesn’t work here.

I’m concerned that something so simple isn’t automatically possible in Julia w/o calling other packages…

16 posts - 11 participants