Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
i want to add 2 numbers of int and double data types. but how it can be possible?
Posted
Comments
Richard C Bishop 19-Apr-13 15:04pm    
You can't, you will get an error. So, converting is your best bet. I would suggest coverting the int to a double so you do not lose accuracy of the number.

This should help you, you will need to convert one or the other.

http://stackoverflow.com/questions/5254357/double-and-integer-conversion[^]
 
Share this answer
 
Numbers of two different type can not be added directly. You will have to convert one of the numbers to the 'other' type and do the addition.

In java (and in fact most other languages), the values will be added automatically by converting the int to double, and the result will be double. If you don't want the automatic conversion to take place, you need to cast to do the conversion the way you want.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900