Re: .Net: This Site Will Keep Me From Posting On List For a While

  • From: "Littlefield, Tyler" <tyler@xxxxxxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Wed, 18 May 2011 12:43:49 -0600

I found a slight issue with one of their articles, and I'm not sure if my method is better; I've used this before though. They are showing a way to get the length of integers, and they use a lot of if statements to check for the value. so: my suggestion is something like this:

int GetLength(int num)
{
int len = 0;
if (number < 0)
{
len ++;
}
len += log10(num)+1;
return len;
}
This means that you can pass a number up to whatever the max int holds, and it'll return it without needing all those if statements. As you can probably see, it'd break if you added an extra digit to the number that wasn't covered in their if statement.
On 5/18/2011 12:08 PM, Homme, James wrote:

http://www.dotnetperls.com/

Jim

Jim Homme,

Usability Services,

Phone: 412-544-1810.


This e-mail and any attachments to it are confidential and are intended solely for use of the individual or entity to whom they are addressed. If you have received this e-mail in error, please notify the sender immediately and then delete it. If you are not the intended recipient, you must not keep, use, disclose, copy or distribute this e-mail without the author's prior permission. The views expressed in this e-mail message do not necessarily represent the views of Highmark Inc., its subsidiaries, or affiliates.


--

Take care,
Ty
my website:
http://tds-solutions.net
my blog:
http://tds-solutions.net/blog
skype: st8amnd127
My programs don't have bugs; they're randomly added features!

Other related posts: