0

Hey guys,
I need to find the length of a long variable (how many numbers it holds).
So if the variable holds: '1234567890' then I want to return an int value
of '10'. varName.Length() doesn't work, and I haven't found anything from
google or msdn.

Thanks for the help,

- WolfShield

5
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by WolfShield
0

I need to find the length of a long variable (how many numbers it holds). So if the variable holds: '1234567890' then I want to return an int value
of '10'.

One way to do this is with Math.Log10. There's a trick to getting the right answer, though... look at the example output on the linked page for clues.

0

@Mitja Bonca:
Your answer does not solves the question.
Your string length is 10, while the equivalent long length is only 9.

0

int length = myLongVar.ToString().Length;

Thanks you! Works like a charm!

- WolfShield

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.