简体   繁体   中英

Would a double to int type conversion be considered implicit type conversion?

Let's say I converted double x to an int, which can be done automatically through truncation. Would this be considered implicit conversion still? Is implicit conversion not being able to translate the actual value from one type to another type without losing any accuracy to that value. In this case would I not be losing the decimal part to x's value? I could not find anything specific in the java docs about this, so I thought to ask here:

double x = 420.69;
int y = x;

That is not an implicit conversion and this will result to compiler error.

double x = 420.69;
int y = x;

Since double is a bigger data type than int, it needs to be down-casted.

double x = 420.69;
int y = (int)x;

However,all the digits after the decimal will be lost.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM