qshinoの日記

Powershell関係と徒然なこと

書式出力 by powershell

書式付き出力

-f 演算子

書式文字列 -f 引数

例) “Hi, {0}! I give you {1:d2} Yen. rn” -f “Taro”, 20

書式文字一覧

c 通貨
d 10進数  精度は最小桁数
e 浮動小数点数 n.nen精度=小数部桁数
f 浮動小数点数 n.nnn 精度=小数点以下
g 浮動小数点数 ne±n 精度=有効桁数
n 3桁コンマ付き
p パーセント
r 精度維持
x 16進数
0 対応文字がない場合0表示
# 不要な場合表示されない

参考

https://msdn.microsoft.com/powershell/reference/5.1/Microsoft.PowerShell.Core/about/about_Operators

http://dobon.net/vb/dotnet/string/inttostring.html

http://d.hatena.ne.jp/newpops/touch/20051126/p1

http://dobon.net/vb/dotnet/string/inttostring.html

msdn

https://msdn.microsoft.com/ja-jp/library/system.string.format(v=vs.110).aspx

http://stackoverflow.com/questions/9904352/how-to-create-printf-effect-in-powershell