Hi Ranchers, I was using NumberFormat for making the minimum integer digit to be 15. I encountered a NumberFormatException while converting back to Double. Now my real Requirment is to enable some calculation for values more than 10 digits. Here is the code. Where am i going wrong. Obviously the NumberFormat will give a value with like say "1,500,000,000,000,000" and when i convert this, i get NumberFormatException.
Now is there a method which will give me a Double value and also parsed value.
Jeff Albertson
Ranch Hand
Joined: Sep 16, 2005
Posts: 1780
posted
0
Double.valueOf is not expecting a String containing commas.
But I think you need to think more about what you are doing. A Format object, like one of type NumberFormat is there to parse strings into numbers or format numbers as string, or both.
There is no emoticon for what I am feeling!
Sri Ram
Ranch Hand
Joined: Oct 03, 2005
Posts: 118
posted
0
Thanx Jeff, Still i am not able to figure out the solution. Let me put it this way, I have a String which is a number of 15 Digits length. Now, I want to do some calculation on that, hence i am converting to a Double. Now it becomes 1.5E15. I cant do any calculation with this. I want number as 1500000000000000. So what is that i have to do??
Originally posted by Sri Ram: ...it becomes 1.5E15. I cant do any calculation with this. I want number as 1500000000000000...
These are just different representations of the same quantity. Do your calculations. Then when you want to display a result, use the format method to give a nice-looking String representation.
Sri Ram
Ranch Hand
Joined: Oct 03, 2005
Posts: 118
posted
0
Originally posted by marc weber:
These are just different representations of the same quantity. Do your calculations. Then when you want to display a result, use the format method to give a nice-looking String representation.
Marc, I am passing the value to a third party API which accepts String. The loanAmount goes as "1.5E15|GHB" where as i have to send "1500000000000000|INR".
Now when the API parses that value, its giving me an Exception. Hence i have to pass the value the same way i enter it in UI.
Harshil Mehta
Ranch Hand
Joined: Mar 17, 2005
Posts: 64
posted
0
Ram,
Marc, I am passing the value to a third party API which accepts String. The loanAmount goes as "1.5E15|GHB" where as i have to send "1500000000000000|INR".
I don't think that the string "|GHB" in "1.5E15|GHB" is required. Is it so?
Sri Ram
Ranch Hand
Joined: Oct 03, 2005
Posts: 118
posted
0
Originally posted by Harshil Mehta: Ram,
I don't think that the string "|GHB" in "1.5E15|GHB" is required. Is it so?
U see i have to pass Loan Amount along with its Currency. Hence thats very much mandatory. Thats y i am getting this problem. If its just double or value, i could have passed it without any problem.
Jeff Albertson
Ranch Hand
Joined: Sep 16, 2005
Posts: 1780
posted
0
Two examples: each takes string "123456789012345", converts it to a number, of some sort, doubles it and converts the result back to a string.