import Data.List (dropWhileEnd) noZeroes :: Int -> Int noZeroes 0 = 0 noZeroes n = (read . dropWhileEnd (== '0') . show) n
And the output:
main = do print (noZeroes 0) -- 0 print (noZeroes 9070) -- 907 print (noZeroes 210000) -- 21 print (noZeroes 10210) -- 1021 print (noZeroes 1450) -- 145 print (noZeroes 960000) -- 96 print (noZeroes 1050) -- 105 print (noZeroes (-1050)) -- -105
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Haskell
And the output: