double to long

double to long

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
public class DoubleToLong {

public static void main(String args[]){

// first example - converting double to long using longValue() method
double d = 102.9520;
long l = (new Double(d)).longValue();
System.out.println("double value=" + d + ", long=" + l);

// second example - rather simple just cast double to long
double bill = 293.05;
long myBill = (long) bill;
System.out.println("double value=" + bill + ", long=" + myBill);


// third example - rounding double value to long in Java
double dbl = 3421.56;
long rnd = Math.round(dbl);
System.out.println("double value=" + dbl + ", long=" + rnd);

}
}

// Output
// double value=102.952, long=102
// double value=293.05, long=293
// double value=3421.56, long=3422

  doublejava
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×