how to count a number of digits.

조회 수: 10 (최근 30일)
komal Bhandari
komal Bhandari 2011년 11월 3일
답변: Melisa Sahin 2020년 6월 23일
How to count a number of digits in a given number withoud using numel and length(num2string()). probably use for loop or while loop.

채택된 답변

Walter Roberson
Walter Roberson 2011년 11월 3일
Well, there is log10(). Or there is counting digits upward until your number is smaller than 10^digits. There are other counting methods too.
One question you are going to have to deal with is what to do if the number is negative. Another question to deal with is what to do if the number is between -1 and +1, such as 0.00043
  댓글 수: 4
komal Bhandari
komal Bhandari 2011년 11월 3일
i know but i mean to say if there any word to describe the no value situation..
komal Bhandari
komal Bhandari 2011년 11월 3일
I got it sir. do not worry.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Jake Bolanski
Jake Bolanski 2011년 11월 3일
I'd go with what Walter mentioned. However, in general length is the ideal way to go.
  댓글 수: 1
Walter Roberson
Walter Roberson 2011년 11월 3일
length() of the formatted string is considerably slower than log10.

댓글을 달려면 로그인하십시오.


Melisa Sahin
Melisa Sahin 2020년 6월 23일
How counts of number digits use a recursion function ?

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by