Meet Gaurav wrote:String f = "000000234";
Long la= new Long(f).longValue;
prefix zero's are missing.. I want the zero's
Then keep the value as a String. Some 'numbers' are not actually numbers. Examples are telephone numbers and credit card number which only contain decimal digits but they are not numbers and should not be treated as numbers. One distinguishing question is - do you need to be able to do arithmetic using these 'numbers' ? If the answer is no then don't treat them as numbers; just treat them as Strings.
Retired horse trader.
Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
Meet Gaurav wrote:that is some code. We badly required that in long
Why! A long is a number stored in two's compliment binary; note binary and not decimal. It contains no formatting information so once you have parsed a String to a long the resulting long has no knowledge of whether it was derived from a hex string, decimal string, binary string, octal string or via a calculation. You can reconstruct the original string only if you know exactly how many decimal places one started with. An easy way to do this is to format it using String.format() but you do need to know how many decimal places you started with and this is not NOT NOT available from the long.
You have to realize there is a difference between how a number is stored, and how it is displayed. the valued of the number '2' is the same regardless of whether I write it as "2", "two", "II", or "000000000000000000000000000000000000000000000000000000000000002".
When you store it as an Integer, you are storing the VALUE. you are trying to combine the storing of the value with storing the display - and you can't. it simply doesn't work that way.
If you need the leading 0's, you will have to store it as a string. you MAY be able to do what you want with the printf specifier, but that will generally require you to specify the total number of digits to display.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com