[erlang-questions] casting float to integer

ok <>
Mon May 14 01:45:02 CEST 2007


Concerning float->integer conversion, clearly round/1 and trunc/1
are not enough, and floor/1 and ceil[ing]/1 should also be provided.
Until they are, you can find relatively simple code for them in xmerl,
which I paraphrase:

     floor(X) ->
         case trunc(X)
           of Y when Y > X -> Y - 1
            ; Z            -> Z
         end.

     ceiling(X) ->
         case trunc(X)
           of Y when Y < X -> Y + 1
            ; Z            -> Z
         end.




More information about the erlang-questions mailing list