How to remove decimal??

30 ビュー (過去 30 日間)
baby
baby 2012 年 5 月 12 日
コメント済み: Dyuman Joshi 2025 年 11 月 20 日
Hello,,
i wanna know how to remove decimal??
Example a = 2.0000
how to remove zero beside point so it will be a = 2??
please help me
  1 件のコメント
Oleg Komarov
Oleg Komarov 2012 年 5 月 12 日
Note that a is most likely not exactly 2, so the question is, do you want to "display" only the integer part or do you want to "drop" the decimal?

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

採用された回答

Oleg Komarov
Oleg Komarov 2012 年 5 月 12 日
To make it clear:
a = 2.00000000001
a =
2.0000
Displaying the integer part ( ans is a char), but a retains the fraction:
sprintf('%.f',a)
ans =
2
Dropping the fraction ( ans is same class as a):
fix(a)
ans =
2

その他の回答 (1 件)

Fabio
Fabio 2012 年 5 月 12 日
As Oleg says if you want to 'display' the integer part just cast to String with num2Str() function: http://www.mathworks.it/help/techdoc/ref/num2str.html
If you want to drop the decimal part you can use round() function: http://www.mathworks.it/help/techdoc/ref/round.html
  8 件のコメント
Walter Roberson
Walter Roberson 2025 年 11 月 19 日
Dyuman Joshi
Dyuman Joshi 2025 年 11 月 20 日
Is it possible that @Luisa wanted to vote on @Walter's response?

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

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by