Asked by Hamilton
on 18 Jun 2013

I would like to print a number with the following format:

.0000000E+00

MATLAB prefers the following:

0.0000000E+000

Is there a way to solve this issue?

*No products are associated with this question.*

Answer by Jan Simon
on 18 Jun 2013

Accepted answer

Java offers more methods to influence the output. See:

Answer by Pourya Alinezhad
on 18 Jun 2013

fprintf('%1.5s',0.1) 1.5 stands for 5 decimal places.1 is for full number. s==scientific you could easily find a way to this problem if you were a c proogrammer...

Jan Simon
on 18 Jun 2013

No, according to the documentation '%s' means 'string', not 'scientific'. I assume you mean '%e' for the scientific notation.

**But** to my surprise the output is exactly the same (tested under 2009a, 2011b). This means that '%s' has the undocumented feature to act like '%e' when it gets numbers as input. Strange.

Anyhow, Hamilton asks for an omitted leading zero and a 2 digit exponent. While the first is ugly and provokes unexpected errors, such that it will hopefully not implemented, the second is the default in non-PC versions of Matlab and in the newest release R2013a.

Pourya Alinezhad
on 18 Jun 2013

Jan Simon
on 19 Jun 2013

@Pourya: And obviously your assumption is not really wrong. Thanks for this interesting new piece of information.

Of course TMW did not implement `fprintf` from scratch but relies on existing libraries. Therefore even known bugs like buffer overflows and other undocumented features like %s with numbers appear in Matlab.

Opportunities for recent engineering grads.

## 0 Comments