フィルターのクリア

How would I modify the output for the answers in the program I've written?

1 回表示 (過去 30 日間)
Aaron
Aaron 2012 年 7 月 22 日
I've created a simple program to convert inches to centimeters and pounds to kilograms and I would like to reduce the number of digits after the zero. Problem is I'm not sure how for this problem?
inches = input('Please enter the height in inches: ');
pounds = input('Please enter the weight in pounds: ');
if inches <= 0
display('Height must be greater than zero!');break;
elseif pounds <= 0
display('Weight must be greater than zero!');break;
end
[Centimeters,Kilograms] = convert_height(inches, pounds)
I get the answers in order (within brackets) but I'm also getting way too many digits than I need.

採用された回答

Jan
Jan 2012 年 7 月 22 日
編集済み: Jan 2012 年 7 月 22 日
Either limit the number of shown digits by
format short g
(see: help format), or display your data explicitly:
[Centimeters,Kilograms] = convert_height(inches, pounds);
fprintf('%.3f %.3f', Centimeters, Kilograms);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by