I’ve never gotten anything unwanted on any of my Macs, though I’m a fairly cautious person. My sister is incredibly malware-prone, however, to the point that we had to completely wipe her Windows-based computer at least three times. She hasn’t had any real problems since we switched her over to an Apple laptop, even though her surfing habits haven’t changed at all.
Buying a Mac is more expensive, though, so you need to ask yourself how much being malware-free is worth to you. A change in habits and a good anti-malware program might be just as good as a different computer.