0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

知っていて当たり前-04 出力形式

Last updated at Posted at 2022-08-01

知っていて当たり前-04 出力形式

1. 書式付き出力 @printf

using Printf
@printf("n = %05d, x = %.7f", 11, sqrt(2))
n = 00011, x = 1.4142136
@printf("t = %.7g, df = %.7g, p-value = %.7g\n", 2.321, 14, 0.32456)
t = 2.321, df = 14, p-value = 0.32456

2. 書式付文字列 @sprintf

x = sqrt(2)
@sprintf("n = %05d, x = %.7f", 11, x)
"n = 00011, x = 1.4142136"
@sprintf("pi = %.15g", pi)
"pi = 3.14159265358979"

3. 書式付文字列,出力 format()

# import Pkg; Pkg.add("Formatting")
using Formatting

n = 123
format("n = {:05d} pi = {:.7e}", n, pi)
"n = 00123 pi = 3.1415927e+00"
print(format("n = {:05d} pi = {:.7e}", n, pi))
n = 00123 pi = 3.1415927e+00

4. 補間演算子 $

特定の場合 $変数,一般の場合 $(式)

変数,式の評価結果を表示する。

println("x = $x, x^2 = $(x^2)")
x = 1.4142135623730951, x^2 = 2.0000000000000004
0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?