adding trailing 0s to inputted numbers

40 ビュー (過去 30 日間)
Paige Berrigan
Paige Berrigan 2022 年 9 月 19 日
回答済み: Eric Delgado 2022 年 9 月 19 日
Is there a way to add trailing 0s after they are inputted in MATLAB (ex turning 4 -> 4.0 or 4.00?) my code wont work unless the sigfigs match but i found rounding them in the matrix using M = round(M,4,"decimals") or M = round(M,4,"significant") just keeps it at the same integer value.
Thank you!
  1 件のコメント
Matt J
Matt J 2022 年 9 月 19 日
編集済み: Matt J 2022 年 9 月 19 日
The number of trailing zeros displayed in the command window is unrelated to how much precision M actually has. We need a more full description (with code) of the problem you are encountering.

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

回答 (1 件)

Eric Delgado
Eric Delgado 2022 年 9 月 19 日
You have to use strings to control the number of decimals.
sprintf('%.1f', 4)
ans = '4.0'
sprintf('%.2f', 4)
ans = '4.00'
sprintf('%.6f', 4)
ans = '4.000000'

カテゴリ

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

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by