velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Dekany <ddek...@freemail.hu>
Subject Re: comparing monetary value
Date Wed, 16 Oct 2002 18:52:27 GMT
Wednesday, October 16, 2002, 3:04:38 PM, Anders Lindback wrote:

> Daniel Dekany skrev:
[snip]
>> I guess we have already seen that sometimes you need decimal values in
>> representation tasks (money...). The list-readers who don't want
>> decimals also admit this when they show workarounds like valueInCents.
>> Why is it better to force designers (and programmers) to play with
>> $valueInCents+tools, than simply providing decimal support? Why is it
>> less error prone and nicer to complicate things with those multiplied
>> values (force designers to always keep in mind, that what is 10.25 in
>> real-world, is 1025 here...), than simply use decimals? Does it make
>> sense?
>
> It makes perfectly sense since computors are digital and are very poor
> to represent floating point numbers. Fractions are a pain in the ass
> - one of the reasons for BigDecimal is too remedy that problem. 

And who said that Velocity should not use BigDecimal? I said that it
should support decimals (numbers like: 10.25), not that it should use
2 based floating point for that.

> Many number that you think would be easy to represent in a computer 
> are not easy to represent given todays FPU.  This is especially true
> when you start talking about respresenting money with floats. 
>
> For example you can get a situation where 2 + 2 != 4 when using
> with floating point numbers. (2+2 may becomes 3.9999999999999 instead. )

Well, I guess it was an accidental bad example, so just to prevent
misunderstandings: as all integers can be represented exactly in 2
based number system, so 2+2 will be exactly 4 if you use 2 based
floating point.


--
To unsubscribe, e-mail:   <mailto:velocity-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:velocity-user-help@jakarta.apache.org>


Mime
View raw message