Given a large positive integer represented as a string str. The task is to round this number to the nearest multiple of 10.
Input: str = “99999999999999993”
Input: str = “99999999999999996”
Approach: A solution to the same problem has been discussed in this article which will not work for large numbers. When the number is large and represented as strings we can process the number digit by digit. The main observation is that if the last digit of the number is ≤ 5 then only the last digit will get affected i.e. it will be replaced with a 0. If it is something greater then 5 then the number has to be rounded to some next higher multiple of 10 i.e. the last digit will be replaced with a 0 and 1 will have to be added to the rest of the number i.e. the number represented by the sub-string str[0…n-1] which can be done by storing carry generated at every step (digit).
Below is the implementation of the above approach:
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Round the given number to nearest multiple of 10
- Nearest prime less than given number n
- Nearest greater number by interchanging the digits
- Divide two integers without using multiplication, division and mod operator | Set2
- Round-off a number to a given number of significant digits
- Nearest prime number in the array of every array element
- Find Nth number in a sequence which is not a multiple of a given number
- Nth number whose sum of digit is multiple of 10
- Number of triplets such that each value is less than N and each pair sum is a multiple of K
- Check if a number is multiple of 5 without using / and % operators
- Smallest N digit number which is a multiple of 5
- n'th multiple of a number in Fibonacci Series
- Check whether a very large number of the given form is a multiple of 3.
- An efficient way to check whether n-th Fibonacci number is multiple of 10
- Smallest multiple of a given number made of digits 0 and 9 only
- Smallest multiple of N with exactly N digits in its Binary number representation
- Reduce the number to minimum multiple of 4 after removing the digits
- Write an Efficient Method to Check if a Number is Multiple of 3
- Nearest element with at-least one common prime factor
- Replace all consonants with nearest vowels in a string
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.