How to convert double value to int value?

515 ビュー (過去 30 日間)
Mira le
Mira le 2023 年 3 月 14 日
編集済み: Dyuman Joshi 2023 年 3 月 14 日
Hi everyone
I have probelm in my matlab code
I want to convert double value to int
d= 5.2 the result will be d=5
thank you

採用された回答

Dyuman Joshi
Dyuman Joshi 2023 年 3 月 14 日
編集済み: Dyuman Joshi 2023 年 3 月 14 日
If you want to round the number -
d=5.2;
%smallest integer less or equal to input
floor(d)
ans = 5
%nearest integer to the input
round(d)
ans = 5
If you want to convert the number from double to an integer data type -
class(d)
ans = 'double'
%Choose an integer data type and use the number as input
D=int32(d)
D = int32 5
class(D)
ans = 'int32'

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by