str2num and commas

13 ビュー (過去 30 日間)
Leor Greenberger
Leor Greenberger 2011 年 10 月 3 日
Hi. str2num doesn't seem to convert '20,000' to 20E3. Instead, it becomes a vector of 2 elements: 20 and 0. Is there a way around this or should I replace the comma in the string with '' before doing string2num? Thanks!

採用された回答

Krishna
Krishna 2011 年 10 月 3 日
I think str2num considers '20' and '000' as two different strings because of the comma. What is the output that you are looking for? if you use str2double it returns 20000 . Hope that serves your purpose.
  1 件のコメント
Leor Greenberger
Leor Greenberger 2011 年 10 月 3 日
AH! Yes, I was looking for '20,000' to be converted to 20000.

サインインしてコメントする。

その他の回答 (1 件)

Krishna
Krishna 2011 年 10 月 3 日
OK then I think str2double will solve your problem.

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by