Brady Dean
Brady Dean

Reputation: 3573

Remove last digit from number

I'm trying to write dropLastDigit :: Integer -> Integer

Eg dropLastDigit 123 == 12 and dropLastDigit with any single digit returns 0

Upvotes: 0

Views: 1077

Answers (2)

djechlin
djechlin

Reputation: 60748

Just divide the number by ten.

dropLastDigit :: Integer -> Integer
dropLastDigit n = div n 10

Upvotes: 8

w.b
w.b

Reputation: 11228

dropLastDigit :: Integer -> Integer
dropLastDigit n  
        | (abs n) < 10 = 0
        | otherwise = read $ init $ show n

Upvotes: 0

Related Questions