[PLUG] Re: [PJUG Javamail] Re-resolved: OT: Formula For Determining # Of Digits . . .
Prashant Kumar
prashant at supplychainge.com
Fri Feb 18 20:28:28 UTC 2005
Speaking of efficieny, how efficient is Math.log10() ? How about
x = the number itself
int count = 0;
while (x >= 1) {
x = x/10;
count++;
}
return count;
On Fri, 2005-02-18 at 11:27, Robb Shecter wrote:
> Jon LeVitre said:
> > It will depend on the distribution or your data, but if the data is
> > random, Travis's method will be more efficient.
>
> Ok, if we're going to really get geeky here, :-) let's consider space as
> well as time efficiency:
>
> Another problem with the easy string-based solution could be object
> creation. The OP's original problem mentioned a number like '032', so it
> sounds like it's a string. So the operation would be;
>
> String -> Integer -> String -> Compute length
>
> Two new objects would be created per execution.
>
> By the way, JDK 1.5 has a new method, Math.log10() ... which doesn't
> suffer from the rounding error.
>
> Robb
> _______________________________________________
> Web Site - http://www.pjug.org/
> Javamail mailing list
> Javamail at pjug.org
> http://www.pjug.org/mailman/listinfo/javamail
--
**********************************************************************
All content of this email, including attachments, is confidential and
meant solely for use by the intended recipient in a manner conforming
to any non-disclosure agreement(s) that the intended recipient may
have with SupplyChainge Inc.
**********************************************************************
More information about the PLUG
mailing list