Effacer les filtres
Effacer les filtres

Convert a string to number

25 vues (au cours des 30 derniers jours)
Lily
Lily le 5 Fév 2014
Commenté : Lily le 6 Fév 2014
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 commentaires
Patrik Ek
Patrik Ek le 5 Fév 2014
Exactly. You could try
a=1.1111111;
a
b=2.2222222;
format long;
a+b
Lily
Lily le 6 Fév 2014
nice, thx :)

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 5 Fév 2014
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.

Plus de réponses (1)

Wayne King
Wayne King le 5 Fév 2014
Modifié(e) : Wayne King le 5 Fév 2014
how about just using format long
data = '0.0782238';
data = str2num(data);
format long
data

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by