-1

How to display long numbers without scientific notation in Matlab?

format long g doesn't help

>> A=single([1456267123000 16.5])
A =
  1×2 single row vector
    1.456267e+12            16.5
>> format long g
>> A
A =
  1×2 single row vector
    1.456267e+12            16.5

I would expect the output like this

    1456267123000           16.5
Dims
  • 47,675
  • 117
  • 331
  • 600
  • Could you give an example of what output you're trying to get? Would you like it to be displayed like that for all outputs or just in tables (or custom classes)? If it's a custom class, you should be able to override its `disp` (or `display`, I can't remember) function to use `sprintf` with the desired format... – Dev-iL Sep 17 '18 at 15:55
  • Table is 1x2 row vector, not a custom class. It contains numbers. I wan't all numbers displayed without exponential (scientific) notation. – Dims Sep 19 '18 at 11:04

2 Answers2

4
  • If you can do with displaying just two decimals, you can use format bank:

    >> format long
    >> pi*1e6
    ans =
         3.141592653589793e+06
    >> pi*1e25
    ans =
         3.141592653589793e+25
    
    >> format bank
    >> pi*1e6
    ans =
        3141592.65
    >> pi*1e25
    ans =
     31415926535897934939029504.00
    
  • Or use the more explicit and flexible sprintf approach:

    >> sprintf('%.7f', pi*1e6) % fixed-point, 7 decimals
    >> disp(sprintf('%.7f', pi*1e6))
    3141592.6535898
    

    If you just want to display the result you can also use, as noted by @Dev-iL,

    >> fprintf(1, '%.7f\n', pi*1e6) % fixed-point, 7 decimals
    3141592.6535898
    

    or even

    >> fprintf('%.7f\n', pi*1e6) % fixed-point, 7 decimals
    3141592.6535898
    
Luis Mendo
  • 110,752
  • 13
  • 76
  • 147
2

You might want to try mat2str which allows you to specify the desired number of digits of precision, and also works for matrices. For example:

>> mat2str(pi, 30)
ans =
    '3.14159265358979311599796346854'

>> mat2str([1456267123000 16.5], 20)
ans =
    '[1456267123000 16.5]'
Dev-iL
  • 23,742
  • 7
  • 57
  • 99