how to get floating point number upto 4 decimal points
이전 댓글 표시
hi i have an array of floating point numbers of type double...for example x=[ 0.8462 0.4906 0.9422 0.2054 0.6154 0.8923 0.3622 0.8710 0.4237 0.9206 0.2757 0.7528] how to limit the values upto 4 decimal points.
x11=(round(x*10000))/10000; does not work
채택된 답변
추가 답변 (1개)
Guillaume
2017년 1월 30일
In what way does
x11 = round(x*10000)/10000 %could be simply replaced by round(x, 4)
not work?
>>round(pi*10000)/10000
ans =
3.1416
>>round(pi, 4)
ans =
3.1416
If you are talking about how the numbers are display, note that it has nothing to do with the actual value stored in the number. You use the format command to tell matlab how to display the numbers. Personally, I use
format shortg
댓글 수: 4
bhan stokes
2017년 8월 23일
can we limit the precision value of floating point numbers upto two or three decimal value.. like if it is .237654...can be limited to .2300000(can or cannot be follow by zeroes)
Steven Lord
2017년 8월 23일
Walter Roberson
2017년 8월 23일
Also note that round() only finds the closest representable number, which will seldom be exactly the value being looked for. It is not possible to represent 0.23 (23/100) exactly in finite binary floating point.
Jan
2019년 4월 3일
i used 'shortg' before my string and i got the limited number string ... provided command was helpful for me . thank you !!!!!
@Vithal Bable: Please use flags only to inform admins and editors about inappropriate contents like spam or rudeness. Thanks.
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!