Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

how to divide two ints and get a double java

/*Now, there are several ways we can try to get precise 
double value (where num and denom are int type)*/

//with explicit casting:
double d = (double) num / denom;
double d = ((double) num) / denom;
double d = num / (double) denom;
double d = (double) num / (double) denom;
//but not double d = (double) (num / denom);

//with implicit casting:
double d = num * 1.0 / denom;
double d = num / 1d / denom;
double d = ( num + 0.0 ) / denom;
double d = num;    d /= denom;
/*but not double d = num / denom * 1.0;
and not double d = 0.0 + ( num / denom );*/
Comment

how to divide a double in java

System.out.print(5d/4d);
Comment

PREVIOUS NEXT
Code Example
Java :: how to check whether a character is vowel in java 
Java :: has integer java 
Java :: @data lombok 
Java :: kotlin string interpolation 
Java :: open file java 
Java :: android use attribute color programmatically 
Java :: java get sub array 
Java :: javafx textarea how to make smaller 
Java :: sorting an arraylist 
Java :: euclids algoritm java gcd 
Java :: how to convert string to boolean in java 
Java :: make frame visible java 
Java :: delete ending part of the string java 
Java :: java encrypt string 
Java :: byte array to base64 string 
Java :: putting scanner into an array 
Java :: get today date in java 8 
Java :: how to do the maximum of three numbers in java 
Java :: AmazonS3ClientBuilder 
Java :: reverse array java 
Java :: string replace java 
Java :: android studio constraint layout proportional height 
Java :: java random number between 2 values inclusive 
Java :: java read directory 
Java :: java how to get all threads 
Java :: getcurrencyinstance java example 
Java :: java remote debug 
Java :: square root of a number in java without sqrt 
Java :: declaration of double array in java 
Java :: string tokenizer java 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =