Write a function called truncate It is passed 2 parameters a

Write a function called truncate. It is passed 2 parameters, a float f and an integer d. The function truncates f so that it has d digits to the right of the decimal point. For example:

You may assume that the second parameter d will be a positive integer.

Solution

Below is the Funtion about the same

double truncate(double d, int n)
   {
      double k=Math.pow(10,n); System.out.println(k);
      int aux = (int)(d*k);
      double result = aux/k;
      return result;
   }

Write a function called truncate. It is passed 2 parameters, a float f and an integer d. The function truncates f so that it has d digits to the right of the de

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site