How can i use round function to change decimal value to integer ?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Maria
el 15 de Sept. de 2022
Comentada: Maria
el 15 de Sept. de 2022
Hi all!
i used the function "round" in order to round values in matrix, but it does not display the required result.
for example i have
x=1.5919 1.0e+06 *
i used
A=round(x)/(10^6)
i get this
X=1.5919 ,but the result i want is X=2.
Thanks in advance
0 comentarios
Respuesta aceptada
Walter Roberson
el 15 de Sept. de 2022
format long g
x = 1.5919 * 1.0e+06
round(x/10^6)
If you are wanting to round to 1 significant digit, then it gets a bit more complicated in vectorized form
x = [pi*10^6, exp(1)*10^-5, -sqrt(2)*10^2, -inf, inf, 0, nan].'
scale = 10.^floor(log10(abs(x)));
scale(scale == 0 | ~isfinite(scale)) = 1;
A = round(x ./ scale) .* scale
Más respuestas (0)
Ver también
Categorías
Más información sobre Get Started with MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!