Motivated by the work of [K. Girstmair, A "popular" class number formula, Amer. Math. Monthly 101(10) (1994) 997-1001; K. Girstmair, The digits of 1/p in connection with class number factors, Acta Arith. 67(4) (1994) 381-386] and [M. R. Murty and R. Thangadurai, The class number of Q(root - p) and digits of 1/p, Proc. Amer. Math. Soc. 139(4) (2010) 1277-1289], we study the average of the digits of the l-adic expansion of 1/n whenever n is a product of two distinct primes or a prime power. More explicitly, if l > 1 is an integer such that gcd(l, n) = 1, and suppose that 1/n = Sigma(8)(k=1) x(k)/l(k) is the l-adic expansion of 1/n, then we establish the average of the digits of the l-adic expansion of 1/n in terms of (l - 1)/2 and the "trace" of generalized Bernoulli numbers B-1,B-X, where.'s are odd Dirichlet characters modulo n. As a consequence of these results, we recover two well-known results of Gauss and Heilbronn (see Theorems 1.6 and 1.7).