Decimals being truncated SOMETIMES
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Sriram_Kanala
Posted On:   Wednesday, July 7, 2004 06:57 AM

Hi, I'm using a JSP screen to make some updates to the database. This screen contains data related to 10 items. When I enter the cost of 1 item as 9.75 and submit the page, it's storing only 9.00 in the database (data type of that column in SQL Server 2000 is numeric(8,2)). But this problem is occuring only at some instances. I have been trying to figure out exactly when this problem occurs, but unable to. There is another screen where I make updates item by item. That means, only single item data is updated from here. From this screen, if I input the cost of Item 1 as 9.75 and submit it, it's saving 9.75 in the db ALWAYS. Now, I tried to figure out what is t   More>>

Hi,



I'm using a JSP screen to make some updates to the database.
This screen contains data related to 10 items.
When I enter the cost of 1 item as 9.75 and submit the page, it's storing only 9.00 in the database (data type of that column in SQL Server 2000 is numeric(8,2)).



But this problem is occuring only at some instances. I have been trying to figure out exactly when this problem occurs, but unable to.



There is another screen where I make updates item by item. That means, only single item data is updated from here. From this screen, if I input the cost of Item 1 as 9.75 and submit it, it's saving 9.75 in the db ALWAYS.



Now, I tried to figure out what is the difference between screen 1 and screen 2.



Screen 1 has multiple items - so the data of all these items is being pushed into a vector. The cost is being considered as Double in Java code.



Screen 2 has only one item - so there is NO usage of vector. Directly, the cost if being updated.



So, I've come to the point where I want to know if using Vector can cause such problems at few instances (pl. note that this problem is occuring only at sometimes, not always).



Has anyone faced this kind of problem?



Is using Vector the root cause of this intermittent problem?



And another point I would like to mention is in the Java code I've used Double type - where as in SQL, I have numeric(8,2).
Correct Java Object Type for SQL numeric (8,2) is java.Math.BigDecimal. But thinking that Double would be sufficient for my data, I've used Double. Is this a possible reason for this intermittent problem?



Any clue in this regard would be very helpful.



Thanks in advance,

SK

   <<Less

Re: Decimals being truncated SOMETIMES

Posted By:   Christopher_Koenigsberg  
Posted On:   Wednesday, July 7, 2004 01:56 PM

I think (?) you never want to use "Double" for currency, because Double is floating point. You need fixed point, if I understand correctly (?). Perhaps try "BigDecimal" ?
About | Sitemap | Contact