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:
- 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
- Nth number whose sum of digit is multiple of 10
- Smallest N digit number which is a multiple of 5
- n'th multiple of a number in Fibonacci Series
- 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
- An efficient way to check whether n-th Fibonacci number is multiple of 10
- Check whether a very large number of the given form is a multiple of 3.
- Smallest multiple of a given number made of digits 0 and 9 only
- 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
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.