数値に桁カンマを挿入することは可能ですか?

7 views (last 30 days)
MathWorks Support Team
MathWorks Support Team on 24 Feb 2010
数値に3桁カンマを挿入する方法を教えてください。

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 24 Feb 2010
カンマを挿入する場合、3桁ずつのグループに分ける必要があります。
下記プログラムをMATLABプログラムとして保存してご利用ください。
または関連ドキュメントよりダウンロードしてご利用ください。
function out = ThousandSep(in)
% Example:
% ThousandSep(1234567)
import java.text.*
v = DecimalFormat;
data = [];
for n=1:length(in)
data{n} = char(v.format(in(n)));
end
out =data;
下記を実行すると、カンマで区切られた文字列が出力されます。
ThousandSep([123456778,2225887])
結果は文字のセル配列となっています。
ans =
'123,456,778' '2,225,887'

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!