• Post Reply Bookmark Topic Watch Topic
  • New Topic
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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Needed 0 preceeded in the numbers

 
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a long variable and where the user can key in values like 0123 or 012222 or 12345

I just wanted to know how to hold these values in long and set it as long or Is thee any other way to approach this
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should use strings to store numbers in that format.
 
Marshal
Posts: 76834
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And you should be able to replace the ??? by something more useful if you look at the Formatter class (comprehensive but difficult to understand) or the Java™ Tutorials section (brief but easy to understand). You cannot store a long as 0000012345 instead of 12345 (in fact the leading 0 in a numeric literal will produce a different value, as you doubtless already know), but you can display it as 00012345 and the Java Tutorials section shows an example very like that.
I have never tried passing "00012345" to a Scanner, nor Long.parseLong("00012345"), but you can probably pass those Strings to be parsed. Try it and see.

Please search these fora; lots of people ask that sort of question.
 
rahulJ james
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have this variable set as long in few places.. Is there anyway I can acheive this by retaining this as long. I have this field as number in teh database as well.

 
Campbell Ritchie
Marshal
Posts: 76834
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have already told you that.
 
author
Posts: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

rahulJ james wrote:I have this variable set as long in few places.. Is there anyway I can acheive this by retaining this as long. I have this field as number in teh database as well.



As already mentioned, a long variable does not hold any formatting -- so ... no.

Henry
 
Yeah, but does being a ninja come with a dental plan? And what about this tiny ad?
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic