Ahora está siguiendo esta publicación
- Verá actualizaciones en las notificaciones de contenido en seguimiento.
- Podrá recibir correos electrónicos, en función de las preferencias de comunicación que haya establecido.
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 =
3.14
Example 2: round PI to 4 decimal places
>> round2(pi,1e-4)
ans =
3.1416
Example 3: round PI to 8-bit fraction
>> round2(pi,2^-8)
ans =
3.1406
Examples 4-6: round PI to other multiples
>> round2(pi,0.05)
ans =
3.15
>> round2(pi,2)
ans =
4
>> round2(pi,5)
ans =
5
Citar como
Robert Bemis (2026). round2 (https://la.mathworks.com/matlabcentral/fileexchange/4261-round2), MATLAB Central File Exchange. Recuperado .
Agradecimientos
Inspiración para: Round to Specified Digits Place, Round to a Specified Number of Significant Digits, Graph Digitzer, Round, Ceil and Floor Matlab-datenumbers, roundfrac, ROUND2DP
Información general
- Versión 1.2.0.1 (1,39 KB)
Compatibilidad con la versión de MATLAB
- Compatible con cualquier versión
Compatibilidad con las plataformas
- Windows
- macOS
- Linux
