Is it possible in matlab to explicitly format the output numbers?

前端 未结 7 1962
太阳男子
太阳男子 2020-12-02 02:07

I know about MATLAB\'s format long, format short, eng ... and so on. But short and long will always display a predefined number of decimals, with

7条回答
  •  死守一世寂寞
    2020-12-02 03:03

    There are two simple solutions:

    1. using the sprintf function:

      str = sprintf('%.4f', myNumber);

    2. using Java-based formatting, which is much more powerful (more information):

      str = char(java.text.DecimalFormat('#.0000').format(myNumber));

提交回复
热议问题