0

I have the below java code snippet:

String str = "0123";
Double dbl = Double.valueOf(str);

The value of dbl become 123.0

But I want to get the value as 0123.0

Is there any way to preserve the leading zero in java?

  • 4
    You can't have leading zeros on doubles. – Zarwan Sep 27 '16 at 07:37
  • Not possible as you want it, not in double – Amer Qarabsa Sep 27 '16 at 07:38
  • what do you pretend keeping theses zeroes? – Luis González Sep 27 '16 at 07:38
  • @LuisGonzález This is actually related to encryption. When I am encrypting few values say 123 the encrypted value will come as 0987; and I want to convert this to Double. Two things here: 1. I can encrypt only string values, that's why I am not encrypting it using the double value as such. 2. The encryption which I am using will preserve the number of digit after encryption – Praveen P Moolekandathil Sep 27 '16 at 08:42
  • @PraveenPMoolekandathil why do you need convert to Double? you need to do some operation ? – Luis González Sep 27 '16 at 11:37
  • @LuisGonzález I want to store the encrypted value into database and in database the field type is double. And whenever the value fetched from database that will be decrypted; the result will be wrong if one digit missed even if it is a leading zero . So each and every digit is important even if it's a leading zero. – Praveen P Moolekandathil Sep 27 '16 at 13:58

0 Answers0