Dear all, might seem and easy question but I cannot figure it out. floor(100*(.58)) [1] 57 where is the trick here? And how can I end up with the right answer? Thanks a lot everybody for your help. Trafim [[alternative HTML version deleted]]
You too have fallen victim to floating point error (see FAQ 7.31).> (100*.58) == 58[1] FALSE> (100*.58) < 58[1] TRUE On Fri, Jul 9, 2010 at 9:46 AM, Trafim Vanishek <rdapamoga at gmail.com> wrote:> Dear all, > > might seem and easy question but I cannot figure it out. > > floor(100*(.58)) > [1] 57 > > where is the trick here? And how can I end up with the right answer? > > Thanks a lot everybody for your help. > Trafim >-- Sarah Goslee http://www.functionaldiversity.org
On Jul 9, 2010, at 8:46 AM, Trafim Vanishek wrote:> Dear all, > > might seem and easy question but I cannot figure it out. > > floor(100*(.58)) > [1] 57 > > where is the trick here? And how can I end up with the right answer? > > Thanks a lot everybody for your help. > Trafim> sprintf("%.20f", 100 * .58)[1] "57.99999999999999289457" See R FAQ 7.31 HTH, Marc Schwartz
On Jul 9, 2010, at 9:46 AM, Trafim Vanishek wrote:> Dear all, > > might seem and easy question but I cannot figure it out. > > floor(100*(.58)) > [1] 57 > > where is the trick here?FAQ 7.31> And how can I end up with the right answer?Define right, please. (There have been several questions in the last week for which FAQ 7.31 was the answer and some of the responses had useful links.) -- David Winsemius, MD West Hartford, CT