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!