in reply to Unexpected results when storing a Math::Round nearest value in MongoDB
what every programmer should know about floating point
Update: IIRC, unless the denominator of your fraction is able to be represented as sums of powers of two (1/2 + 1/8, for example), you end up with an approximation of the value. Many times, this tends to be "close enough". If dealing with money, for example, you will often want to use some other representation than floating point under the hood (an integer representation of millicents or some such comes to mind).
Update 2: As an example REPL - perl -ne 'printf("%.60f\n", $_)'.
Update 3: See My floating point comparison does not work. Why ? for more information
--MidLifeXis
|
|---|