octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #51515] sprintf not rounding correctly


From: Rik
Subject: [Octave-bug-tracker] [bug #51515] sprintf not rounding correctly
Date: Thu, 20 Jul 2017 11:46:26 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:54.0) Gecko/20100101 Firefox/54.0

Follow-up Comment #3, bug #51515 (project octave):

What version of Matlab and what platform (Linux, Mac, Windows) did you test
with?  As Andreas indicated, it may vary simply because of the platform and
the underlying C libraries.

Also, could you test the following:


sprintf ('%1.1g|', [2.5, -2.5, 3.5, -3.5])


Finally, as always, if you want a particular result it is best to code for
that rather than rely on implicit and undocumented defaults which could change
from Matlab version to version.  In this case, there are functions floor,
ceil, round, fix, and roundb so the programmer can get exactly the desired
rounding behavior.  I would recode to


sprintf ('%1.1g', round (x))


if the desired behavior is regular rounding.


    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?51515>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]