Known for portraying Winnie Cooper in the coming-of-age television series "The Wonder Years," actress Danica McKellar has taken on several non-acting roles since then—including mathematician and New York Times best-selling author.

Growing up, the actress says she was always good at math. "I took the AP Calculus BC exam at the end of high school and scored a 5 which the highest score you could get," McKellar told CNBC's "On the Money" in an interview.

But that confidence soon disappeared when she entered college, in part because she thought she "didn't look the part" as someone who would major in mathematics. However, McKellar stuck with it and graduated summa cum laude from UCLA, where she co-authored the theorem Percolation and Gibbs States Multiplicity for Ferromagnetic Ashkin–Teller Models on Z2.

After graduating in 1998, McKellar went back to acting, but she also became an advocate for math and stem education. Over a decade ago, McKellar testified to a Congressional subcommittee about how to draw more women into science and math.

Her initial lack of confidence in college prompted her to write math books aimed at middle school and high school girls. Those works included her New York Times bestsellers "Math Doesn't Suck," "Kiss My Math," and "Girls Get Curves."

McKellar said she wanted young women to know "you don't have to be limited by the stereotypes in your head about who's going to be good at math." Even if you don't love math, McKellar recommended to keep at it.

"It exercises the problem solving part of your brain, which will help you better able to pursue your dreams, whatever they might be," the author and actress said.

"You don't have to choose between being fabulous and fun and being smart – they go hand in hand," she added.