Click here to Skip to main content
13,057,084 members (43,448 online)
Rate this:
Please Sign up or sign in to vote.
See more:
i want to add 2 numbers of int and double data types. but how it can be possible?
Posted 19-Apr-13 7:57am
richcb 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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

This should help you, you will need to convert one or the other.[^]
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170728.6 | Last Updated 22 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100