如何检查值是整数还是小数 [英] How to check the value is integer or decimal

查看:102
本文介绍了如何检查值是整数还是小数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何检查数量值是否为小数



例如:



数量可能是0.5或1.0或1.5



如果数量是0.5或1.5,



我想加0.5得到整数值

数量是1.0或2.

解决方案

有很多方法可以做到这一点。例如:



  double  d =  5  0 ; 
bool isInt = d ==( int )d;

你也可以使用modulo。



  double  d =  5  0 ; 
bool isInt = d% 1 == 0 ;


您好,



您可以使用数学函数。

how could I check the quantity value is decimal or not

For Example:

Qty may be 0.5 or 1.0 or 1.5

if Qty is 0.5 or 1.5,

I want to plus 0.5 to get integer value as
Qty is 1.0 or 2.

解决方案

There are any number of ways to do this. For example:

double d = 5.0;
bool isInt = d == (int)d;

You can also use modulo.

double d = 5.0;
bool isInt = d % 1 == 0;


Hi,

you can use Math functions.


这篇关于如何检查值是整数还是小数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆