To roundoff a number. A program requried.

//input1: 5.8 output1: 6

//input2: 7.44 output2: 7

urgent

0 votes

import java.io.*;

import static java.lang.Math.*;

public class A {

// Function to round - off the number

static void Round_off(double N, double n)

{

int h;

double l, a, b, c, d, e, i, j, m, f, g;

b = N;

c = floor(N);

// Counting the no. of digits to the left of decimal point

// in the given no.

for (i = 0; b >= 1; ++i)

b = b / 10;

d = n - i;

b = N;

b = b * pow(10, d);

e = b + 0.5;

if ((float)e == (float)ceil(b)) {

f = (ceil(b));

h = (int)(f - 2);

if (h % 2 != 0) {

e = e - 1;

}

}

j = floor(e);

m = pow(10, d);

j = j / m;

System.out.println("The number after rounding-off is "

+ j);

}

// Driver main function

public static void main(String args[])

{

double N, n;

// Number to be rounded - off

N = 139.59;

// No. of Significant digits required in the no.

n = 4;

Round_off(N, n);

}

}

import static java.lang.Math.*;

public class A {

// Function to round - off the number

static void Round_off(double N, double n)

{

int h;

double l, a, b, c, d, e, i, j, m, f, g;

b = N;

c = floor(N);

// Counting the no. of digits to the left of decimal point

// in the given no.

for (i = 0; b >= 1; ++i)

b = b / 10;

d = n - i;

b = N;

b = b * pow(10, d);

e = b + 0.5;

if ((float)e == (float)ceil(b)) {

f = (ceil(b));

h = (int)(f - 2);

if (h % 2 != 0) {

e = e - 1;

}

}

j = floor(e);

m = pow(10, d);

j = j / m;

System.out.println("The number after rounding-off is "

+ j);

}

// Driver main function

public static void main(String args[])

{

double N, n;

// Number to be rounded - off

N = 139.59;

// No. of Significant digits required in the no.

n = 4;

Round_off(N, n);

}

}

...