Given a positive number n (n > 1), round-off this number to a given no. of significant digits, d.
Input : n = 139.59 d = 4 Output : The number after rounding-off is 139.6 . The number 139.59 has 5 significant figures and for rounding-off the number to 4 significant figures, 139.59 is converted to 139.6 . Input : n = 1240 d = 2 Output : The number after rounding-off is 1200 .
What are significant figures?
Each of the digits of a number that are used to express it to the required degree of accuracy, starting from the first non-zero digit, are called as significant figures.
Since there are numbers with large number of digits, for example, = 3.142857143, so in order to limit such numbers to a manageable number of digits, we drop unwanted digits and this process is called rounding off.
Significant digits include all the digits in a number falling in one of the following categories –
- All non-zero digits.
- Zero digits which-
- lie between significant digits.
- lie to the right of decimal point and at the same time to the right of a non-zero digit.
- are specifically indicated to be significant.
The following table shows numbers and no. of significant digits present in them –
Rules for Rounding-off a Number
To round off a number to n significant figures-
- Discard all digits to the right of nth significant digit.
- If this discarded number is-
- less than half a unit in nthplace, leave the nth digit unchanged.
- greater than half a unit in the nth place, increase the nth digit by unity.
- exactly half a unit in the nth place, increase the nth digit by unity if its odd, otherwise leave it unchanged.
The following table shows rounding-off a number to a given no. of significant digits –
The number after rounding-off is 139.6
This article is contributed by Mrigendra Singh. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Unset least significant K bits of a given number
- Find most significant bit of a number X in base Y
- Steps to reduce N to zero by subtracting its most significant digit at every step
- Invert the Kth most significant bit of N
- Find smallest number with given number of digits and sum of digits under given constraints
- Numbers of Length N having digits A and B and whose sum of digits contain only digits A and B
- Minimum digits to be removed to make either all digits or alternating digits same
- Maximize the given number by replacing a segment of digits with the alternate digits given
- Find the Largest number with given number of digits and sum of digits
- Number of digits in the nth number made of given four digits
- Find the average of k digits from the beginning and l digits from the end of the given number
- Sum of the digits of square of the given number which has only 1's as its digits
- Count numbers in given range such that sum of even digits is greater than sum of odd digits
- Count of integers in a range which have even number of odd digits and odd number of even digits
- Number formed by deleting digits such that sum of the digits becomes even and the number odd
- Check whether product of digits at even places is divisible by sum of digits at odd place of a number
- Count of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M
- Check if the sum of digits of number is divisible by all of its digits
- Even digits Sum and Odd digits sum divisible by 4 and 3 respectively
- Numbers with sum of digits equal to the sum of digits of its all prime factor