Showing only 2 decimals

12 visualizaciones (últimos 30 días)
Jakob Sievers
Jakob Sievers el 28 de Feb. de 2013
Hi guys
Trivial question, I am sure, but I can't figure this one out: I am rounding numbers to show only two decimals by:
sprintf('%.2f',number)
This doesnt work for values on the order of 1e^{-n} where n is large. The result then becomes 0.00. How do I preserve the knowledge of 1e^{-n} while still only showing two decimals?
Cheers!

Respuesta aceptada

Daniel Shub
Daniel Shub el 28 de Feb. de 2013
Is this what you want?
sprintf('%.2e',0.123456789e-10)
ans =
1.23e-11
  1 comentario
Jakob Sievers
Jakob Sievers el 28 de Feb. de 2013
Exactly! Thanks! I knew the solution would be simple! :)
Cheers

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements 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!

Translated by