# Formatting of result values.

1 vue (au cours des 30 derniers jours)
Jiapeng le 18 Sep 2022
For example, x=0.0012345678.
How can I get x to be in the format 0.123457*10^(-2). There are six significant digits and if more than six decimal places, which are converted to standard format by rounding.
Thank you！
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponse acceptée

Star Strider le 18 Sep 2022
That is not a format MATLAB will do automatically.
I wrote a utility function for my own use for such requirements —
x=0.0012345678;
lod = 1;
rfd = @(x,lod) [x*(10.^(-fix(log10(x)-lod+1))), fix(log10(x)-lod+1)]; % Anonymous Function Creating Reformatted Number
Out = sprintf('%.6fE%+d', rfd(x,lod)) % Character Vector With Formatted Output
Out = '0.123457E-2'
Experiment with it if necessary. MATLAB maintains full precision internally regardless of the way the numbers are formatted.
.
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Plus de réponses (1)

John D'Errico le 18 Sep 2022
You cannot write it in that form, at least not easily. Yes, you could write a formatting code. But you would need to write it, separating out the exponent, then building it as a string.
You CAN use an exponential format, like this:
format short e
x=0.0012345678
x =
1.2346e-03
But if you want that specific 10^-2 form, that will take more work.
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### 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!

Translated by