how to get floating point number upto 4 decimal points
Show older comments
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
Accepted Answer
More Answers (1)
Guillaume
on 30 Jan 2017
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 Comments
bhan stokes
on 23 Aug 2017
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
on 23 Aug 2017
Walter Roberson
on 23 Aug 2017
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
on 3 Apr 2019
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.
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!