如何检查double值是否没有小数部分 [英] How to check if a double value has no decimal part

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

问题描述

我有一个双重值,我必须在我的UI显示。
现在的条件是double = 0的十进制值例如。 - 14.0
在这种情况下,我必须在我的UI上只显示14。
此外,字符的最大限制为5。



eg.- 12.34整数值可以不大于2位数,而十进制值也是如此



可以做最好的方法是什么?

解决方案

你可以这样做: d%1 == 0 看看是否有一些 double d 是整个。


I have a double value which I have to display at my UI. Now the condition is that the decimal value of double = 0 eg. - 14.0 In that case I have to show only 14 on my UI. Also, the max limit for characters is 5 here.

eg.- 12.34 the integer value can be no bigger than 2 digits and so is the decimal value for our double.

What could be the best way of doing this?

解决方案

You could simply do this: d % 1 == 0 to see if some double d is whole.

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

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