theartha
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.
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.
That's just a string representation. Format it (as a String) however you want it
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
i.e: select year from employee where employeeAmt = "2.147483647E7" -- fails
select year from employee where employeeAmt = "21474836.47" -- pass
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>>i.e: select year from employee where employeeAmt = "2.147483647E7" -- fails
... but you wouldn't do it that way. You'd use a PreparedStatement
... but you wouldn't do it that way. You'd use a PreparedStatement
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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).
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).
Value is correct only.