• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

String to numeric and back  RSS feed

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This should be easy - but I'm having trouble working through it.

here's the situation. I have a field which MUST be 7 characters in length, is numeric in nature, and needs to have arithmetic functions applied. So, I guess I have multiple questions:

1) is there any way to "fix" the length of a numeric data type buy padding with "0"?
2) if not, how can I take the string value (example 0000100), convert to numeric so I can add 1 (I've succeeded in this step and the result comes back "101"), then convert back to "0000101" ??

Thanks in advance !
Rob
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think you can fix the length, but you can convert it to a number, do your operation, then convert it back. To convert it back goes something like this:


I don't have the API in from of me, so that may not be precisely right, but if you look at the java.text.DecimalFormat class API, you should be able to get the rest of it.

Derek
[ September 24, 2004: Message edited by: Derek Baker ]
 
Rob Gee
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Derek - took a little tinkering, but it works great !!

r
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!