Module is used for using variables in just the context of one input.One option for your code is:

f[n_]:=Total[Last/@NestWhileList[{Floor[#[[1]]/10],Boole[IntegerPart[#[[1]]/10]

Š#[[1]]/10]}&,{n,0},IntegerPart[#[[1]]/10]¹0&]**,1,¥,1**]

which repeatedly divides the number by ten and checks whether it is equal to its floor, returning elements of the form {IntegerPart of last # over 10, 1 if last # over 10 equals IntegerPart of last # over ten, 0 otherwise}. It then takes the last part of each of these elements, and sums them.

Another option that I just thought of that uses module (I reread your post and noticed the comment about module) is:

**f[n_]:=Module[{a=0,n1=n},If[n1==0,a=1];While[n1¹0,If[Mod[n1,10]Š0,a++];n1=IntegerPart[n1/10]];a]**

which does the same thing. In order for it to work for negative numbers, use integerpart rather than floor, because floor rounds down, integerpart rounds toward zero.

This works by setting a=0 and n1=n. Then it checks if n1 already equals zero, setting a to one if it is, because zero has one zero in it. If n1 is not already equal to zero, it checks whether n1 mod 10 equals zero, if it is it increments a, and then it divides n1 by ten, takes the integer part of it and repeats until n1 equals zero.

This works for all integers.