フィルターのクリア

How to check class double number for non-zero decimals in an if statement?

5 ビュー (過去 30 日間)
rbme17
rbme17 2017 年 6 月 16 日
コメント済み: Star Strider 2017 年 6 月 16 日
I'm writing a GUI, and entries for specific edit text boxes are not supposed to contain decimals. I'm trying to use an if statement to tell whether or not a class double has non-zero numbers after the decimal point.
My goal is to give feedback with a 'msgbox' so that if a decimal is entered, the user is notified to enter an integer instead. Does anyone have any tips on how to properly define a condition to check for decimals in an if statement?
Thanks!

採用された回答

Star Strider
Star Strider 2017 年 6 月 16 日
One approach would be to use the rem or mod functions:
x1 = 42.00;
y1 = rem(x1,1)
x2 = 42.42;
y2 = rem(x2,1)
y1 =
0
y2 =
0.42
Then test if the result is 0.
  2 件のコメント
rbme17
rbme17 2017 年 6 月 16 日
This is exactly what I was looking for, thanks!
Star Strider
Star Strider 2017 年 6 月 16 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by