Link to home
Start Free TrialLog in
Avatar of theartha
thearthaFlag for United States of America

asked on

String to Double conversion

Hi There,

I am trying to set "002147483647" into a setter of type Double.

i.e amount.setAmount(new Double(002147483647/100);

private Double amount;
public void seAmount(Double amount) {
      this.Amount = amount;
}

but when I tried to get the value, I am getting as 2.147483647E7

Please advice.

Thanks.
Avatar of cmalakar
cmalakar
Flag of India image

I believe it just prints it in scientific form.

Value is correct only.
Avatar of CEHJ
That's just a string representation. Format it (as a String) however you want it
Avatar of theartha

ASKER

@cmalakar: Yes the value is correct, but I can't use that value to insert or get a value from database.

i.e: select year from employee where employeeAmt = "2.147483647E7" -- fails
 select year from employee where employeeAmt = "21474836.47" -- pass


ASKER CERTIFIED SOLUTION
Avatar of cmalakar
cmalakar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>i.e: select year from employee where employeeAmt = "2.147483647E7" -- fails

... but you wouldn't do it that way. You'd use a PreparedStatement
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Suraj_Mathew
Suraj_Mathew

In your operation

amount.setAmount(new Double(002147483647/100);

2147483647 / 100 = 21474836.47

So taking the above explanantion , you can see that the result is having 8 integer digits and 2 decimal digits , which is the reason why the result (output) is converted to exponential form (E).