to round a number to n-decimal places, in C, I use the following method:-
#include <stdio.h>
void main()
{
float a=0.12685;
int n=3;
printf("%.*f",n,a);
}
NOTE:- only '*' can be used to pass a value to the float format specifier. statements like %.xf give error.
Is there a way to do the same thing in Java?