Using string() on double values without automatic rounding?
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
When i use string() with double values, the number is converted to a string where the number is rounded to four decimals, even when there are more decimals in the original double value. Image:

I am currently writing a conversion script where i need the extra decimals. Is it possible to disable this automatic rounding?
Thank you.
0 commentaires
Réponse acceptée
Matt J
le 8 Mai 2023
even when there are more decimals in the original double value
There are no more decimals in the original double value. A double value can only have 15 digits of precision.
Plus de réponses (1)
Stephen23
le 9 Mai 2023
Rather than slow NUM2STR and then STRING, for a scalar the simpler and more efficient approach is to just call SPRINTF:
sprintf("%.9f",123.123123123)
For non-scalar values use COMPOSE:
0 commentaires
Voir également
Catégories
En savoir plus sur Characters and Strings dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
