Mathematics as Plot
Science fiction deals with speculative science, and given how close math is to science, it's no surprise that some science fiction involves creative uses of math. Mathenauts, an anthology of short stories, features several of this kind. For example, the title of Larry Niven's “Convergent Series” refers to series of numbers such as 1/2 + 1/4 + 1/8 … The numbers get so small, so quickly, that in some sense they do “add up” to one, even though there are infinitely many of them. The narrator invokes a similar process to banish a pesky demon.
Mathematics as Distraction
Niven opens his story with a discussion of magic, only reaching the mathematical image at the very end. In contrast, stories can set up a mathematical tone only to have the numbers be overshadowed later on. The first Mathenauts story, Isaac Asimov's “1 to 999,” at first searches for meaning in a plain sequence of numerals, 1 through 999. In fact, there is no mathematical significance to them at all—the twist of the story is that the numbers are meant to be interpreted as words. Here, mathematics provides a roadblock, rather than a solution.
Another short story (in a different anthology) called “The Mathematicians” also uses this tactic. Over three-and-a-half pages, Arthur Feldman builds to a punchline of “they were great mathematicians. So, they multiplied.”
There's a case to be made for including the use of one particular number in the Hitchhiker's Guide to the Galaxy series under this category, rather than strictly “humor.” The characters' (and readers') futile attempts to ascribe meaning to a number that appears out of the blue could qualify this as a deflection on Douglas Adams' part (although not, like Asimov, to a new meaning that eventually solves the mystery).
This is by no means limited to science fiction or fantasy, but portraying someone as a mathematician can open the door to various nerdy/aloof stereotypes. Greg Egan's Diaspora uses lots of mathematics as a plot device (which goes over my head), but the final pages portray a character seeking out the isolation of working on math. Similarly, Feldman's alien mathematicians are not initially aware of human emotions.
Cultural allusions
At least in series set in some variant of the real world as we know it, superstitions attached to real-life numbers are likely to carry over to the fantastic world. Just as seven is considered a lucky number by many people today, seven is considered “the most powerfully magical number” in Harry Potter. Among the many uses of seven in the book include the seven school years of Hogwarts, with real-world significance of there being seven books in the series. Similarly, thirteen is viewed as an unlucky number in Hogwarts as well as in reality.
Some hints in the Wheel of Time series point to that world being a far-flung past or future of our own, in which case the seven Ajahs of the White Tower or the Seven Towers of Malkier might qualify.
Numbers as organizing themes
On the other hand, Garth Nix' Seventh Tower series (there are seven towers, one for each color of the rainbow) has six books.
Alien units
Aliens are not from Earth; it doesn't make sense to expect their systems of measurement to coincide with Earth units. In the Animorphs series, the alien Ax consistently notes that Earth units are alien to him. From book 18, The Decision:
<Actually, it has only been one of your hours and eighteen minutes,> [Ax] said helpfully.
<One of our hours,> Marco said. <You know, they really are your hours now, too. This is Earth. You're stuck here. Go ahead and set your watch to local time.>
I'm surprised I can't think of more aliens who use base 8 or 12 or anything other than 10 off the top of my head. This is probably a function of my taste, as demonstrated by the overlap with the next large category...
Numbers and humor
Playing the “different units” game for laughs can get even more outlandish than Ax and Marco, above. The humorous Outernet series does this as well. When characters aren't asking each other to “give me eighteen,” we have lines like:
“On the planet Zhilqueeg, for example, there are eighty neehees in a gajug, fifty gajugs in a twip, twenty-two twips in a yuryur, and so on, bringing about the common expression on Zhilqueeg: “There just aren't enough twips in the yuryur.””
At least two of those three examples have the decency to be in multiples of ten, a trait not shared by the Harry Potter series' use of 29 Knuts to a Sickle, and 17 Sickles to a Galleon. (Although I've heard this is actually supposed to be a parody of the British monetary system.)
The first few Discworld books written make a running joke of characters not saying the number that's one more than seven, because of its powerful magical properties. The Hitchhiker's Guide to the Galaxy's use of a number might qualify, too (see above).
Misuses of math
Not all uses of numbers are, in my opinion, very well-written ones. Examples that might otherwise fall under a different category can stretch the limits of belief.
In Animorphs, the alienness of units is called into question when the protagonists receive the power to become animals. This comes with a warning; they will be trapped in the form of an animal they morph into if they stay longer than two hours. Since this technology was invented by Ax's species, and we know that Earth units are alien to them, it's implausible that the limit should have worked out to exactly two of our Earth hours.
Inconsistency, as well as implausibility, can plague descriptions of alien units. For humorous effect, Outernet defines a “standard galactic year” as “About twenty Earth minutes” (to exaggerate a character's problems with interest rate) in book two. By book four, however, “100 Gala-years” is being used interchangeably with “a hundred years.”
Moreover, the “underlying theme” of an alien world can feel a little too much like home. In the Mistborn trilogy, sixteen is introduced as an important number for the planet (and, Sanderson's other works suggest, universe as a whole); there are more or less sixteen basic metals used in the magic system, and characters stricken by a mysterious illness fall sick for sixteen days. Fine, but having the protagonist realize “oh my goodness! Sixteen percent of our armies, exactly, got sick! This is a sign!” felt a little strained to me. Perhaps this is just my mathematical nitpickery coming into play, but sixteen percent makes the slight leap of faith that the characters would be as familiar with percents and the base-10 system as we are. Since they're humans, that's not too farfetched, but I would have preferred “one in sixteen,” which feels a little more natural.
Old School
It's possible that the two biggest-deal uses of math in fantasy or science fiction both came in the 1800s. One of them is Flatland, which uses a mathematical adventure in the second dimension to poke fun at Edwin Abbott Abbott's Victorian society. The other began life as a short draft, before its author, a conservative math professor, added some more important scenes. And the rest is history.