In the code, I have

int a = 62;
int b = 132;
double c;
c = a/b;

This will generate the c value in the double format as 0.469696968793869

In fact, I only need to an approximation representation of c like 0.4697

Can you let me know how to do that?

Member Avatar for ztini
double c = new DecimalFormat("#.####").format(a/b);

or you could use Math.round(), but I personally like DecimalFormat better because you can define currency prefixes, commas, etc

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.