How can I specify the number of significant digits in an output variable

39 visualizaciones (últimos 30 días)
Philip
Philip el 13 de Sept. de 2017
Respondida: Ameer Hamza el 22 de Abr. de 2018
I have a number, say 170803134921, in a character array. When I convert the array to a number it shows up with scientific notation.
temp = '170803134921'
str2num(temp)
ans = 1.708031349210000e+11
I would like to the number that is output in ans to display the same number of significant digits as the string did (12 digits) without the decimal point and scientific notation. How do I achieve this?

Respuestas (2)

Fangjun Jiang
Fangjun Jiang el 13 de Sept. de 2017
format LongG
str2num(temp)

Ameer Hamza
Ameer Hamza el 22 de Abr. de 2018

You can use vpa() for arbitrary precision in your calculations. In your case

vpa(temp)

gives,

ans = 170803134921.0

You can set the precision using digits(). You will need symbolic math toolbox installed, to use these functions.

Categorías

Más información sobre Logical 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