• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String to numeric and back

 
Rob Gee
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
 
Derek Baker
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic