How to choose number of decimal places
33 views (last 30 days)
Show older comments
Hi there i am recieving a udp packet as a string and im opening a port to read it, which i receive using the below code.
fopen(UDPComIn);
data=fscanf(UDPComIn, '%f');
Using this i receive a number of -35.3630 which is the number, but it's missing a couple of the decimal places. The actual number i am looking for is -35.3630445. Using the code below i can extract all the information as a string.
fopen(UDPComIn);
data=fscanf(UDPComIn, '%s');
latitude = str2double(data)
Data = '-35.3630445', however latitude = -35.3630.
How do i receive all the decimal numbers as they are important?
0 Comments
Accepted Answer
Stephen23
on 26 Oct 2017
Edited: Stephen23
on 26 Oct 2017
Don't worry, MATLAB has not eaten your digits! You should not confuse how data is displayed with how data is stored in memory, because these are two totally different things. In your case, all of those digits (and more!) are stored correctly in memory. You can change the format to change what digits are displayed in the command window:
>> lat = str2double('-35.3630445');
>> format shortg
>> lat
lat = -35.363
>> format longg
>> lat
lat = -35.3630445
You see: all of the digits are stored the whole time, even if you choose not to display them all.
0 Comments
More Answers (0)
See Also
Categories
Find more on Data Type Conversion 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!