JUST Take integer value number from decimal value
183 ビュー (過去 30 日間)
古いコメントを表示
if my output is a decimal value but i just want to take the integer value only
HOW am i going to do that>???
eg
a=4.321323
i just want take 4 , what code should i write??
0 件のコメント
採用された回答
José-Luis
2012 年 11 月 6 日
a = -3.1145
your_val = fix(a)
If you also want it to work for negative numbers.
その他の回答 (1 件)
Thomas
2012 年 11 月 6 日
a=4.321323;
out=floor(a)
1 件のコメント
John D'Errico
2020 年 11 月 3 日
@Rokeya Mumtahana Mou:
If you have a different question , then ask it as a question of your own.
However, there are several functions you should read about.
round: rounds to the nearest integer.
floor: round down toward -inf
fix: round towards zero
ceil: round upwards
You want either ceil or round, depending on the behavior you wish to see. Thus, would 4.49 map to 5, or to 4? ceil would produce always the larger integer, whereas round find the nearest integer.
And of course, fix and floor are identical for positive numbers.
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!