RPCConsole::setTrafficGraphRange() had similar code which I replaced with this new util function.  There is similar code in BitcoinGUI::setNumBlocks() but it formats the string differently and uses less precision.