# RoundOff a number

To roundoff a number. A program requried.

//input1: 5.8 output1: 6

//input2: 7.44 output2: 7

urgent

answered Oct 1, 2019 by naveed
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);

}

}
answered Oct 1, 2019 by (290 points)
Good morning. Could you please help me better understand what you are looking for? Are you wanting an end user to enter a (decimal) number and have that round (up or down) to the nearest whole number? Which programming language are you looking for this in? DAVE