How to prevent a decimal number being rounded to a whole number?

馋奶兔 提交于 2019-12-25 01:09:38

问题


I am using this code to get the numeric data from the file I am studying:

[FileName,PathName]= uigetfile('*.txt*','Files to Study');

%fullfile puts pathname and filename into one file so it can be used to
%import data from the chosen file 
file =fullfile(PathName,FileName);

A = [];
fid = fopen(file);

tline = fgets(fid);
while ischar(tline)
    parts = textscan(tline, '%d;');
    if numel(parts{1}) > 0
        A = [ A ; parts{:}' ];
    end
    tline = fgets(fid);

end

fclose(fid);
 X = A(:,2)
 Y = A(:,7)  

It works fine, but the issue I am having is: when the numbers are displayed in the command window they have been rounded from numbers with decimal points to whole numbers.

For example from:

165.98  
166.38  
166.78  
167.18  
167.57  
167.97  
168.37  
168.77  
169.17  
169.56  
169.96  
170.36  
170.76  
171.16  
171.55  
171.95  

to this:

 166  
 166  
 167  
 167  
 168  
 168  
 168  
 169  
 169  
 170  
 170  
 170  
 171  
 171  
 172  

Is there some change I could make to my code to display the original data rather that the rounded whole numbers?

来源:https://stackoverflow.com/questions/23492523/how-to-prevent-a-decimal-number-being-rounded-to-a-whole-number

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!