Output of valid decimal places in Julia language

Asked 2 months ago, Updated 2 months ago, 4 views

I'd like to print a valid number of 5 digits in Julia's language, but how should I print it?
The following will not work.

 round (0.0625, digits=6)
#0.0625

In this case, the desired value is 0.062500.
If there is no number greater than or equal to 0 for the specified valid number, it will be supplemented by 0.
Do these tool functions exist?

julia

2022-09-30 11:03

1 Answers

As with other common programming languages, you can specify the number of digits in printf.

If I were to apply it to the example question, it would be @printf"%.6f"0.0625.

reference:
Printf-The Julia Language

Usage

@printf([io::IO], "%Fmt", args...)

Example

julia>@printf "Decimal two digits %.2f "1.23456
Decimal two digits 1.23


2022-09-30 11:03

If you have any answers or tips


© 2022 OneMinuteCode. All rights reserved.