How to print 0 without a negative sign in the front? Everytime I want to print 0 it prints -0.000.
6 ビュー (過去 30 日間)
古いコメントを表示
1.0000 0 -0.0000 0 2.0000
0 1.0000 0.0000 0 0
0 0 1.0000 0 6.0000
0 0 -0.0000 1.0000 5.0000
I used format rat at first but then it made my 0's into astericks so then I tried format short which showed me that my error was in the zeros printing as 0.0000 and -0.0000. Could someone please tell me how to get rid of both -0.0000 and 0.0000 and replaced with just a 0.
0 件のコメント
回答 (1 件)
John D'Errico
2021 年 6 月 12 日
編集済み: John D'Errico
2021 年 6 月 12 日
That minus zero is NOT truly zero. It is just a tiny number that is slightly less than zero, but when rounded to only 4 digits for display, it "looks" like a zero.
format short
A = [1 0 -1e-6 0 2;0 1 1e-6 0 0]
As you can see, in the third column, when I used format short, the numbers are shown as -0.0000 and 0.0000, even though they are not zero in either case.
If I use a better format, such as short g or long g, the approximate zeros are now seen to be just small numbers.
format short g
A
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Get Started with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!