Round the given number to nearest multiple of 10 | Program to round the number to the nearest number having one 's digit 0 ; Last character is 0 then return the original string ; If last character is 1 or 2 or 3 or 4 or 5 make it 0 ; process carry ; Return final string ; Driver code ; Function Call
function round ( s , n ) { let c = s . split ( ' ' ) ; if ( c [ n - 1 ] == ' ' ) return s ; else if ( c [ n - 1 ] == ' ' c [ n - 1 ] == ' ' c [ n - 1 ] == ' ' c [ n - 1 ] == ' ' c [ n - 1 ] == ' ' ) { c [ n - 1 ] = ' ' ; return c . join ( " " ) ; } else { c [ n - 1 ] = ' ' ; for ( let i = n - 2 ; i >= 0 ; i -- ) { if ( c [ i ] == ' ' ) c [ i ] = ' ' ; else { let t = c [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) + 1 ; c [ i ] = String . fromCharCode ( 48 + t ) ; break ; } } } let s1 = c . join ( " " ) ; if ( s1 [ 0 ] == ' ' ) s1 = " " + s1 ; return s1 ; } let s = " " ; let n = s . length ; document . write ( round ( s , n ) ) ;