The line is not Wharton's own aphorism offered in her own voice — it is dialogue given to Lily Bart, the beautiful but financially precarious heroine of The House of Mirth, during a bantering exchange with Lawrence Selden about whether she could ever be truly happy among the "idle rich."
Selden immediately punctures Lily's line with a rejoinder — "You might as well say that the only way not to think about air is to have enough to breathe" — making clear the novel treats the sentiment as a clever but self-deceiving rationalization, not a moral endorsed by the author.
"...the only way not to think about money is to have a great deal of it."