programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Jeanne Boyarsky
• Ron McLeod
• Liutauras Vilda
• Paul Clapham
Sheriffs:
• paul wheaton
• Tim Cooke
• Henry Wong
Saloon Keepers:
• Stephan van Hulst
• Tim Holloway
• Carey Brown
• Frits Walraven
• Piet Souris
Bartenders:
• Mike London

# amount of digits entered(without a tokenizer)....

Ranch Hand
Posts: 133
• Number of slices to send:
Optional 'thank-you' note:
Without using a tokenizer, how can I determine the amount of digits in an integer entered by a user? (Say the user enters 123,345. I need to somehow within the program determine that there are 6 digits)

Ranch Hand
Posts: 1067
2
• Number of slices to send:
Optional 'thank-you' note:
Convert to a string and do a length.

Brandi Love
Ranch Hand
Posts: 133
• Number of slices to send:
Optional 'thank-you' note:
how do you do that?

William Barnes
Ranch Hand
Posts: 1067
2
• Number of slices to send:
Optional 'thank-you' note:
With out looking in any books I would guess something like this:

I am not saying that this is the best way, only one way.

(instanceof Sidekick)
Posts: 8791
• Number of slices to send:
Optional 'thank-you' note:
This is probably sloppy, but I concatenate an empty string with a number to make it a string now and then:
int i = 12312312;
int digits = (""+i).length();

mister krabs
Posts: 13974
• Number of slices to send:
Optional 'thank-you' note:

Originally posted by Stan James:
This is probably sloppy, but I concatenate an empty string with a number to make it a string now and then

That is actually the easiest way. You could also use the static toString(int i) method of Integer:
int digits = Integer.toString(i).length();

Brandi Love
Ranch Hand
Posts: 133
• Number of slices to send:
Optional 'thank-you' note:
Thanks guys I ended up just doing a string length.
[ November 03, 2003: Message edited by: Brandi Love ]