Round input to nearest multiple of arbitrary value.
14,1K descargas
Actualizado 1 sep 2016

Ver licencia

Everyone knows about the ROUND function for converting floating point values to their nearest whole number or integer value, but have you ever wanted to round off values to something other than whole numbers? This simple utility function does just that.
Example 1: round PI to 2 decimal places
>> round2(pi,0.01)
ans =

Example 2: round PI to 4 decimal places
>> round2(pi,1e-4)
ans =

Example 3: round PI to 8-bit fraction
>> round2(pi,2^-8)
ans =

Examples 4-6: round PI to other multiples
>> round2(pi,0.05)
ans =
>> round2(pi,2)
ans =
>> round2(pi,5)
ans =

Citar como

Robert Bemis (2024). round2 (, MATLAB Central File Exchange. Recuperado .

Compatibilidad con la versión de MATLAB
Se creó con R13
Compatible con cualquier versión
Compatibilidad con las plataformas
Windows macOS Linux
Más información sobre Logical en Help Center y MATLAB Answers.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Versión Publicado Notas de la versión

Updated license

Minor bug fix (error message typo)


Expanded help text with examples, including binary fraction (analagous to fixed point math).