MATLAB: Numbers to the left of the dot in tab of matlab

Database Toolboxfprintf

Hi everyone, I'm new and I'm not sure how this format works, I don't know if I asked the question correctly but I hope you can help me. I have to calculate iter error sol res in the matlab tab with decimal and integer digits, in fixed and floating point format. how can i know how many digits to the left of the dot I have to put?
example
fprintf('%3d %24.5e %12.2e\n' ,tab')

Best Answer

The %e format always outputs exactly one digit before the decimal place, and outputs a number of decimal places after that according to the format you give, such as 5 decimal places for the %24.5e format. So far that is 1 leading + 5 after decimal [in this case] + decimal place itself, subtotal 7 so far. It always always has a sign character for the exponent, so subtotal 8 now.
If the value is negative, then it will use one place for that. If your leading width such as the 24 in %24.5e is not wide enough to accomodate everything including the leading - then it will use an extra character .
Now we get to the question of how many digits of exponent there are. If I recall correctly, the rule is:
  • if you are on MS Windows, or abs() of the exponent is 100 or greater, then 3 digits of exponent are used
  • if you are on Mac or Linux and abs() of the exponent is 99 or less, then 2 digits of exponent are used
So take the subtotal of 8, add 3 potential digits for exponent, add 1 potential place for sign, for a total of 12 in this case (7 plus number of digits you specified after the period in the %.e format). No value will require more than that.