We systematically measure the dielectric function of atomically thin MoS2 films with different layer numbers and demonstrate that excitonic effects play a dominant role in the dielectric function when the films are less than 5-7 layers thick. The dielectric function shows an anomalous dependence on the layer number. It decreases with the layer number increasing when the films are less than 5-7 layers thick but turns to increase with the layer number for thicker films. We show that this is because the excitonic effect is very strong in the thin MoS2 films and its contribution to the dielectric function may dominate over the contribution of the band structure. We also extract the value of layer-dependent exciton binding energy and Bohr radius in the films by fitting the experimental results with an intuitive model. The dominance of excitonic effects is in stark contrast with what reported at conventional materials whose dielectric functions are usually dictated by band structures. The knowledge of the dielectric function may enable capabilities to engineer the light-matter interactions of atomically thin MoS2 films for the development of novel photonic devices, such as metamaterials, waveguides, light absorbers, and light emitters.