Chandra,
I think the point I am trying to make is that if you store amounts as 
integers in the database, you can avoid a lot of problems with rounding 
errors and the code that is necessary to avoid them in your business logic. 
I have had to add a lot of code to deal with the removal of fractional 
cents every time a multiplication or division operation is done on a value 
and when storing amounts. I've found that its easier just to store the 
amount as an integer and deal with the formatting when displaying the value.

-Richard

At 12:40 PM 5/1/2002 -0500, you wrote:
>I would think (hope, rather) that calculations are not being performed in
>the form beans. While you are correct about rounding errors, this has
>nothing to do with display beans(for want of a better word) For example,
>reading a float/double value from a database and displaying it requires this
>kind of formatting. I think this is what Mark is asking about.
>
>-----Original Message-----
>From: Richard Yee [mailto:[EMAIL PROTECTED]]
>Sent: Wednesday, May 01, 2002 12:35 PM
>To: Struts Users Mailing List
>Subject: RE: Bean Bug?
>
>
>Mark,
>Regardless of how the number is formatted, there will always be a problem
>when handling currency amounts as floating numbers. Multiplication and
>division operations will introduce rounding errors. I have found that it is
>best to store currency amounts as ints and then have code in the beans to
>format the values for display. This also can ease I18n issues when dealing
>with currencies that don't contain decimals.
>
>Regards,
>
>Richard
>
>
>
>At 06:22 AM 5/1/2002 -0400, you wrote:
> >I see your point, but aren't you incurring unnecessary formatting overhead
> >in the presentation tier (to say nothing of ongoing maintenance)?  Any
> >Struts tag that writes to the presentation tier should take such formatting
> >issues into consideration.  For example, the formatting tag that Chandras
> >suggests (or using java.text.NumberFormat in the action) look like good
> >solutions.
> >
> >Mark
> >
> >-----Original Message-----
> >From: Richard Yee [mailto:[EMAIL PROTECTED]]
> >Sent: Tuesday, April 30, 2002 6:55 PM
> >
> >Mark,
> >In continuing with my last email. 1.00 would be stored as 100 in an int.
> >
> >-Richard
> >At 03:52 PM 4/30/2002 -0700, you wrote:
> > >Mark,
> > >To store decimal numbers or any currency for that matter as ints, you
> > >store the values as the smallest unit of currency.  For dollars, this is
> > >0.01 or a cent. You then can avoid any round off errors when doing
> > >multiplication or division.
> > >
> > >Regards,
> > >
> > >Richard
> >
> >--
> >To unsubscribe, e-mail:
><mailto:[EMAIL PROTECTED]>
> >For additional commands, e-mail:
><mailto:[EMAIL PROTECTED]>
>
>
>
>--
>To unsubscribe, e-mail:
><mailto:[EMAIL PROTECTED]>
>For additional commands, e-mail:
><mailto:[EMAIL PROTECTED]>
>
>--
>To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
>For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to