Resultset problem
Hi
I try to get the value from table.
amount =rs.getDouble("amount");
The actual value of amount colum is 15,579,483.65 in table.
But when i getting the value through resultset
this value comes with long decimals like 1.5758559E7
Also i try round of funciton but after using this function its comming the same value
Please help me how can i control the decimals when i getting the resultset values. ?
Thanks
Merlin Rosina
> Hi
>
> I try to get the value from table.
> amount =rs.getDouble("amount");
> The actual value of amount colum is 15,579,483.65 in
> table.
> But when i getting the value through resultset
> this value comes with long decimals like 1.5758559E7
> Also i try round of funciton but after using this
> function its comming the same value
> Please help me how can i control the decimals when i
> getting the resultset values. ?
>
What is the type of your variable 'amount'?
What statement is used when the value is stored/updated in the 'amount' field?
What is the DB data type of the 'amount' column?
For example, if you have used setBigDecimal() of a prepdstmt for a NUMERIC column, you
have to use rs.getBigDecimal() properly.
hiwaa at 2007-7-16 13:47:52 >

Hi
Thanks
What is the type of your variable 'amount'?
double amount=0.0D;
What statement is used when the value is stored/updated in the 'amount' field?
preparedStatement
What is the DB data type of the 'amount' column?
amount number(16,2);
For example, if you have used setBigDecimal() of a prepdstmt for a NUMERIC column, you have to use rs.getBigDecimal() properly
Thankx
Merlina
In case the answers of hiwa and DrClap weren't clear enough:
Variables of type double do not have a format. So saying something like "this value comes with long decimals like 1.5758559E7" doesn't mean anything. The format is not a property of a number.
Only when you print a number, it is formatted in a certain way. You can use a class like java.text.DecimalFormat to control the way a number is formatted when it's printed.
Try something like this:
double amount = 1.575855963E7;
DecimalFormat df = new DecimalFormat("##,###,###.##");
System.out.println(df.format(amount));
NOTE: If you are working with amounts of money and this is a serious application, you should NOT use doubles to store amounts of money. The type double doesn't have infinite precision, and you'll run into rounding problems. Use java.math.BigDecimal instead for amounts of money.