suppose i have number a=5.70787644444 how do i consider just first 2 decimal places in that . that is a=5.70. is it possible?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Pradeep Gowda
el 7 de Feb. de 2015
Comentada: Image Analyst
el 7 de Feb. de 2015
please reply as soon as possible.
Respuesta aceptada
Star Strider
el 7 de Feb. de 2015
One solution:
a = 5.70787644444;
roundn = @(x,n) fix(x.*10.^n)./10.^n; % Round ‘x’ To ‘n’ Digits To The Right Of The Decimal
ar = roundn(a,2)
produces:
ar =
5.70
4 comentarios
Más respuestas (1)
Guillaume
el 7 de Feb. de 2015
a = 5.70787644444;
arounded = round(a, 2)
1 comentario
Image Analyst
el 7 de Feb. de 2015
Yes, but he didn't ask for the rounded value. You probably just thought that since that's the name Star chose - not a good descriptive name in my opinion since it uses fix() instead of round() and fix() does not round in the sense that most people think of rounding.
Ver también
Categorías
Más información sobre Startup and Shutdown en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!