-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Marcin Tyman wrote:
> How to truncate float number after dot? I suppose it would be easy.

Rounding to a certain number of digits works as follows:

Let n be the number of digits following the decimal point you want to
obtain. Then

1. Multiply the number by 10 to the power n (i.e. by 10.0 ** n)
2. Round the number (i.e. use Float#round)
3. Divide the result by 10 to the power n

The latter can either be done by division by 10.0 ** n or by
multiplication by 0.1 ** n.

But as Robert Klemme already noted: It rarely makes sense to actually
round numbers. It usually makes more sense to compute with the available
precision and limit the output to the wanted number of digits.

Anyway, sometimes it makes sense. For example if you are required by law
to round intermediate calculation results to a certain amount of digits.
But in such cases one should not at all use floating point numbers for
the computations. One would rather use integers, fixed-point arithmetics
(as e.g. supported by COBOL) or the Decimal data type from Microsoft's
Common Type System (e.g. supported by C#).

Josef 'Jupp' Schugt
- --
Blog available at http://www.mynetcologne.de/~nc-schugtjo/blog/
PGP key with id 6CC6574F available at http://wwwkeys.de.pgp.net/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iD8DBQFGqK1/rhv7B2zGV08RArEPAJ0Z6ihtrVLvBn0ODryW8Ptu3uqplACfTuT1
muYIWqBXnWKO4ZwEKYMiVik=
=5H5E
-----END PGP SIGNATURE-----