Convert a string to number

14 次查看(过去 30 天)
Hi, I want to convert a string into a number however I don't want to use str2num since I loose extra digits (see example below). Can I use some other MATLAB function?
data = 0.0782238;
s = str2num(data); %Don't want this since s = 0.0782 and I'm loosing three extra digits
  4 个评论
Patrik Ek
Patrik Ek 2014-2-5
Exactly. You could try
a=1.1111111;
a
b=2.2222222;
format long;
a+b

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2014-2-5
str2num() does not lose those extra digits. Instead, you are not displaying the full width of the number. At the MATLAB command line give the command
format long g
and try your code again.

更多回答(1 个)

Wayne King
Wayne King 2014-2-5
编辑:Wayne King 2014-2-5
how about just using format long
data = '0.0782238';
data = str2num(data);
format long
data

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by