Formatting large numbers

You might use StrFormat instead.

marketCap = 1234567;

mktcap = StrFormat("%1.2fM", marketCap/1e6);

Or

function StrFormatMillion(value) {
   cond = value>=1e6;
   fmt = WriteIf(cond, "%1.2fM", "%g");
   denom = IIf(cond, 1e6, 1);
   result = StrFormat(fmt, value/denom);
   return result;
}

marketCap = 1234567;
fmt = StrFormatMillion(marketCap);

PS: Another must read here: