Stuck in exponential notation format

5 ビュー (過去 30 日間)
Oliver
Oliver 2023 年 1 月 31 日
コメント済み: Oliver 2023 年 1 月 31 日
Hello All,
I am struggling to display my answer without scientific notation.
fprintf('Failed due to temperature %0.1d\n',Percentfailtemp)
This will spit out scientific notation in the command window, regardless of the fact that the value of my variable within the workspace is not in scientific notation.
Is there a work around?
Thanks in advance

採用された回答

Walter Roberson
Walter Roberson 2023 年 1 月 31 日
format long g
for Percentfailtemp = [0.011 0.11 1.1 11 110 110.234 100*(1-eps)]
fprintf('Failed due to temperature %0.1d\n',Percentfailtemp)
end
Failed due to temperature 1.1e-02 Failed due to temperature 1.1e-01 Failed due to temperature 1.1e+00 Failed due to temperature 11 Failed due to temperature 110 Failed due to temperature 1.1e+02 Failed due to temperature 1.0e+02
Scientific notation got used precisely in the situations where the input is not an integer. This includes cases such as
100*(1-eps)
ans =
100
That display as integers but are not exactly integers.
Do not use a %d format for values that are not exact integers. If you want to use 1 decimal place, use a %f format
for Percentfailtemp = [0.011 0.11 1.1 11 110 110.234 100*(1-eps)]
fprintf('Failed due to temperature %0.1f\n',Percentfailtemp)
end
Failed due to temperature 0.0 Failed due to temperature 0.1 Failed due to temperature 1.1 Failed due to temperature 11.0 Failed due to temperature 110.0 Failed due to temperature 110.2 Failed due to temperature 100.0
  1 件のコメント
Oliver
Oliver 2023 年 1 月 31 日
That second part was exactly what I needed!
Didnt even realise that I had other options for the letter %

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by