Decimal equivalent of concatenation of absolute difference of floor and rounded | Function to find the decimal equivalent of the new binary array constructed from absolute decimal of floor and the round - off values ; Traverse the givenarray from the end ; Stores the absolute difference between floor and round - off each array element ; If bit / difference is 1 , then calculate the bit by proper power of 2 and add it to result ; Increment the value of power ; Print the result ; Driver Code
function findDecimal ( arr , N ) { let bit , power = 0 , result = 0 ; for ( let i = N - 1 ; i >= 0 ; i -- ) { bit = Math . abs ( Math . floor ( arr [ i ] ) - Math . round ( arr [ i ] ) ) ; if ( bit != 0 ) result += Math . pow ( 2 , power ) ; power ++ ; } document . write ( result ) ; } let arr = [ 1.2 , 2.6 , 4.2 , 6.9 , 3.1 , 21.6 , 91.2 ] ; let N = arr . length ; findDecimal ( arr , N ) ;