Using trunc function in Erlang

Richard Cameron <>
Fri Dec 30 20:24:39 CET 2005


On 30 Dec 2005, at 19:50, Erlang Questions wrote:

> Unfortunately, these numbers represent money in my application :o(

Oh dear. I can only hope that they never represent my money - unless  
you want to round upwards.

The best advice I can offer is: don't use floating point to represent  
money. Use integer arithmetic only (on the cents/pence/euro cents),  
and guard against overflows.

A compromise is to use erlang:round() instead of trunc and you  
*probably* be OK... although I reserve the right to take that back if  
it ever goes wrong.

Richard.



More information about the erlang-questions mailing list