如何将Double直接转换为int? [英] How to convert Double to int directly?

查看:163
本文介绍了如何将Double直接转换为int?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是个愚蠢的问题。我想摆脱 Double 号码的小数部分。但我不能这样做。它显示了不兼容类型的错误。该怎么办?

May be this is silly question. I want to get rid of the fractional part of the Double number. But I cant do that. It shows the error that incompatible types. What to do?

在一行中转换为转换....请帮助谢谢

Double to int conversion in one line....please help thanks

推荐答案

如果你真的应该使用Double而不是double,你甚至可以通过调用获得double的int值:

If you really should use Double instead of double you even can get the int Value of Double by calling:

Double d = new Double(1.23);
int i = d.intValue();

其他已经由Peter Lawreys回答。

Else its already described by Peter Lawreys answer.

这篇关于如何将Double直接转换为int?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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